-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion for selecting all file changes since a revision #64
Comments
Hi @markddavidoff, If I understand it correcly, the existing Update: This may be a duplicate of #85 and #159, fixed in Darker 1.3.0. |
@akaihola -r also requires passing the files you want to black, at least for me, with just |
@markddavidoff you can pass it a directory, and it will check all files in that tree recursively. If that's unclear from the documentation, I consider it a documentation bug that needs fixing! |
I improved documentation in #69. Could you @markddavidoff review that? |
@akaihola I don't want to pass it a directory though, I'd like to explicitly pass it a list of files, the same way i do with black. (my directory has A LOT of files) |
@markddavidoff sorry I don't fully get what your use case is. Is it possible that you've missed the fact that Darker in fact does only reformat files which have been modified compared to the branch you specify using I'll walk you through an example of what Darker does, because I think it somewhat resembles the use case you're describing. Let's say your repository is in $ cd ~/my-repo ; git stat
## my-feature
M setup.py
M setup.cfg
M src/myrepo/__main__.py
M src/myrepo/tests/test_main.py
# ... and so on If you now run $ darker --revision master ~/my-repo then Darker will
You may get a better sense of all the steps Darker does by running it with the Do you think this is anywhere near what you're trying to achieve? |
I believe explicitly darker only formats files which have been modified compared to the branch you specify using --revision and are also in the specified directory ( That last part is the bit that is the point of confusion. since The reason i wanted to specify files, is that I expected |
when i run with darker i can instead run |
If We don't want What you can do is specify the default [tool.darker]
revision = "master"
src = [
"src/mypackage",
"tests/helpers.py",
] Then running $ darker -r master src/mypackage tests/helpers.py |
@markddavidoff you might want to take a look at darker.git.git_get_modified_files() to understand how Darker decides which files to process. When that function is called,
|
This is certainly not the intention. Darker should only consider files listed on the command line, and in those files, only those regions which have changed compared to the commit specified using the Could you give an example of where this is not true? |
hmmm, when i run with more than one file path, i often get an error, perhaps that is why I assumed it did not work as expected. |
@markddavidoff, I would very much like to reproduce that problem on my own laptop. Are you running Darker on an Open Source project so I could try it on the same Git repository? Could you copy-paste what you see on screen? Could you also add the I'm sure I'll be able to help you once I get more information about the problem. |
Hi @markddavidoff, Do you remember this Darker problem from last September? Any new insight into it? |
@akaihola yeah, the main issue is how darker handles new files that are not in the specified previous revision: |
so that's why i ended up running this per-file as that avoids those files that are on disk but not in head. That is also why I wanted to pass a list of specific files, because what I do is run darker for each individual file that is returned from the So i need some way to avoid that fatal path error or some way to fix it. |
Does this match what you're seeing? Apart from maybe suppressing the error from Git, would you like to see Darker behave differently? $ mkdir /tmp/not-in-branch
$ cd /tmp/not-in-branch
$ git init
$ touch README
$ git add README
$ git commit -m "Initial commit"
[master (root-commit) b41a90a] Initial commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README
$ cat >test.py
print( "something to reformat" )
$ darker --diff . --revision=master
fatal: Path 'test.py' exists on disk, but not in 'master'.
--- test.py
+++ test.py
@@ -1 +1 @@
-print( "something to reformat" )
+print("something to reformat")
$ darker --revision=master .
fatal: Path 'test.py' exists on disk, but not in 'master'.
$ cat test.py
print("something to reformat") |
@markddavidoff, Darker 1.3.0 now hides the fatal error from Git. The above example looks like this after upgrading to Darker 1.3.0: $ mkdir /tmp/not-in-branch
$ cd /tmp/not-in-branch
$ git init
Initialized empty Git repository in /tmp/not-in-branch/.git/
$ touch README
$ git add README
$ git commit -m "Initial commit"
[master (root-commit) d6c7f97] Initial commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README
$ cat >test.py
print( "something to reformat" )
$ darker --diff . --revision=master
--- test.py 2021-09-06 18:46:29.418269 +0000
+++ test.py 2021-09-06 18:46:32.399737 +0000
@@ -1 +1 @@
-print( "something to reformat" )
+print("something to reformat")
$ darker --revision=master .
$ cat test.py
print("something to reformat") |
@markddavidoff, I'm closing this issue. Please send a note if you think this issue still exists. |
locally i made a wrapper to call black/darker with
$(git diff --name-only --diff-filter=d\* $(git rev-parse --abbrev-ref HEAD) master -- ':*.pyi' ':*.py')
as the paths argument, which will specify all changes (excluding deletions) on a specific branch.I know not everyone uses git, but i think its pretty useful to have built in for most cases and its easy enough to error when a flag is specified but git is not present and it should be easy enough to tweak to play with the -r flag.
The text was updated successfully, but these errors were encountered: