2

I have a notebook.ipynb with one cell that has the following code def test( ): return "yes"
and another script.py that has one line of code: test="test"

So I run the following command:

black --$(git diff --name-only -- *.ipynb -- *.py) 

My terminal shows one change on the notebook.ipynb and no change on the script.py

How should I use the command git diff --name-only ?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
abdellah
  • 65
  • 1
  • 8
  • 1
    Note that besides fixing up your `git diff`, you probably want a space after the `--` in `black --$(...)` (i.e., `black -- $(...)`). – torek Sep 20 '21 at 23:40

1 Answers1

4

Following "How to filter git diff based on file extensions?", I would first test the diff command alone:

git diff --name-only -- '*.ipynb' '*.py'
                    ^^^
                only one --

Or:

git diff --name-only -- *.{ipynb,py}

Once that is working, you can include the diff command in your more general command.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250