-
Notifications
You must be signed in to change notification settings - Fork 55
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
--revision <branch>...
compares to HEAD, not working tree
#79
Comments
@Carreau @CorreyL @Mystic-Mirage @samoylovfp @CircleOnCircles @Pacu2 @DylanYoung I have a tricky design issue with Darker in #79. Basically the question is how to design command line options for properly comparing the working tree in a feature branch to a main branch. We need to compare to the latest common ancestor of the feature and main branches, because the main branch might have commits after the branch point. But we also want to include the Git staging index and the working tree in the comparison. It would be helpful if anyone could review my line of thought in the issue and give an opinion of what would be a good design here. Thanks! |
'master..' (two dots) compare with head, 'master...' (3dots) compare with the merge-base (aka common ancestor). At least git should do that. I'll reach the thing you point to in more detail. |
Sorry scratch what I said above, it's too early, and that what you said in the other issue. |
Just to clarify, here's a problematic example case: A file has been removed in The solution is to use
|
Currently I'm liking options
Other opinions? |
(ping @jasaarim to let you know what I'm currently wrestling with :) |
Just my two cents, coming into this having read over what's been outlined so far (thanks for such great detail into your thought process btw @akaihola)
This seems to be the most user friendly and obvious option from an outsiders perspective, without greater context of the discussion outside of this issue (if it has been discussed previously). |
I would like to help but, I'm very noob about git. 😓 I use Gitkraken on daily basis. I have difficulties to comprehend. |
@CircleOnCircles, your input may be the most valuable one precisely because of that! It's best if Darker works in an obvious way no matter if you're a Git newbie or a seasoned expert. @CorreyL as said, I like alternative 3 as well. Its only downside is deviating from Git semantics – But, as also said, it will still be possible to say |
In local development work, one use case of darker is to check formatting and linting against the branch point from
master
. This can be achieved using e.g.--revision master...
– but the current implementation compares toHEAD
and ignores uncommitted changes in the working tree and the staging index.This could be fixed by first doing a
git merge-base <branch> HEAD
, followed bygit diff --name-only --relative <revision>... -- <paths>
with<revision>
from the output ofmerge-base
.This requires a bit of parsing for the range given using the
--revision
argument.On the other hand, this would make the meaning of revision expressions different between Git and Darker. In
git diff
, these revision expressions show changes between:<commit>
: the specified<commit>
and the current working tree – you could think<commit>..<working tree>
(although there really isn't an identifier for the current working tree)<commit>..HEAD
:<commit>
and the current last commit, ignoring the staging index and the working tree<commit>...HEAD
:<commit>
and its latest ancestor which is common withHEAD
(ignoring the staging index and the working tree)<commit1>...<commit2>
:<commit1>
and the latest common ancestor of<commit1>
and<commit2
><commit>..
: (alias for<commit>..HEAD
)<commit>...
: (alias for<commit>...HEAD
)So for use in CI, Darker's current
--revision <commit>...
option is fine, because in that situation there shouldn't be anything in the staging index, and no uncommitted changes in the working tree.But for local use, the user probably most often wants to run Darker before committing and does want to include staging index and working tree content in the comparison. Without the
--revision
option, Darker already does this comparison correctly againstHEAD
(the latest commit), but when working on a feature branch, it's probably better to compare against the latest common ancestor of the feature branch and the main branch (e.g.master
). For this we currently have no--revision
expression, and there is none to adopt from Git either.To illustrate the local use case, here's a log of a hypothetical repository in which we probably most often want to compare
(branch point)..(working tree)
, which can be achieved in git by doing agit diff $(git merge-base master HEAD)
:Some of the alternatives to consider:
master...WORKTREE
,master...INDEX
– but this would cause a collision if anyone needed to name their branches or tagsWORKTREE
orINDEX
HEAD
– somaster..
->master..(worktree)
andmaster...
->master...(worktree)
, and default Git behavior can still be achieved with e.g.master..HEAD
andmaster...HEAD
--revision
, but add a separate command line option to use the working tree or staging index instead ofHEAD
as the comparison point when using--revision <commit>..
or--revision <commit>...
, e.g.--git-worktree --revision master...
or--git-index --revision master...
--revision
, but add a separate command line option to use the latest common ancestor when using--revision <commit>
, e.g.-m -r master
or-b -r master
or--merge-base --revision master
The text was updated successfully, but these errors were encountered: