Message ID | 20200425022045.1089291-6-jacob.e.keller@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | None | expand |
Jacob Keller <jacob.e.keller@intel.com> writes: > From: Jacob Keller <jacob.keller@gmail.com> > > git switch with the --orphan option is used to create a new branch that > is not connected to any history and is instead based on the empty tree. > > It does not make sense for completion to return anything in this case, > because there is nothing to complete. Check for --orphan, and if it's > found, immediately return from _git_switch() without completing > anything. > > Add a test case which documents this expected behavior. > > Signed-off-by: Jacob Keller <jacob.keller@gmail.com> > --- > contrib/completion/git-completion.bash | 11 ++++++++++- > t/t9902-completion.sh | 7 +++++++ > 2 files changed, 17 insertions(+), 1 deletion(-) > > diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash > index c21786f2fd00..08d3406cf3e4 100644 > --- a/contrib/completion/git-completion.bash > +++ b/contrib/completion/git-completion.bash > @@ -2223,9 +2223,18 @@ _git_switch () > __gitcomp_builtin switch > ;; > *) > + local track_opt="--track" only_local_ref=n > + > + # --orphan is used to create a branch disconnected from the > + # current history, based on the empty tree. Since the only > + # option required is the branch name, it doesn't make sense to > + # complete anything here. > + if [ -n "$(__git_find_on_cmdline "--orphan")" ]; then > + return > + fi > + > # check if --track, --no-track, or --no-guess was specified > # if so, disable DWIM mode > - local track_opt="--track" only_local_ref=n > if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] || > [ -n "$(__git_find_on_cmdline "--track --no-track --no-guess")" ]; then > track_opt='' > diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh > index a134a8791076..9d02de167219 100755 > --- a/t/t9902-completion.sh > +++ b/t/t9902-completion.sh > @@ -1351,6 +1351,13 @@ test_expect_failure 'git switch - with -C and --no-track, complete all reference > EOF > ' > > +# TODO: completion does not yet recognize --orphan > +test_expect_failure 'git switch - with --orphan, do not complete anything' ' > + test_completion "git switch --orphan " <<-\EOF > + > + EOF > +' > + I am getting "TODO passed" at 7276ffe0 (completion: add test showing subpar completion for git switch --orphan, 2020-04-24), which hasn't hit 'next' yet. Perhaps we got some rebase gotcha here? > test_expect_success 'teardown after ref completion' ' > git branch -d matching-branch && > git tag -d matching-tag &&
On Mon, Apr 27, 2020 at 4:34 PM Junio C Hamano <gitster@pobox.com> wrote: > > Jacob Keller <jacob.e.keller@intel.com> writes: > > > From: Jacob Keller <jacob.keller@gmail.com> > > > > git switch with the --orphan option is used to create a new branch that > > is not connected to any history and is instead based on the empty tree. > > > > It does not make sense for completion to return anything in this case, > > because there is nothing to complete. Check for --orphan, and if it's > > found, immediately return from _git_switch() without completing > > anything. > > > > Add a test case which documents this expected behavior. > > > > Signed-off-by: Jacob Keller <jacob.keller@gmail.com> > > --- > > contrib/completion/git-completion.bash | 11 ++++++++++- > > t/t9902-completion.sh | 7 +++++++ > > 2 files changed, 17 insertions(+), 1 deletion(-) > > > > diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash > > index c21786f2fd00..08d3406cf3e4 100644 > > --- a/contrib/completion/git-completion.bash > > +++ b/contrib/completion/git-completion.bash > > @@ -2223,9 +2223,18 @@ _git_switch () > > __gitcomp_builtin switch > > ;; > > *) > > + local track_opt="--track" only_local_ref=n > > + > > + # --orphan is used to create a branch disconnected from the > > + # current history, based on the empty tree. Since the only > > + # option required is the branch name, it doesn't make sense to > > + # complete anything here. > > + if [ -n "$(__git_find_on_cmdline "--orphan")" ]; then > > + return > > + fi > > + > > # check if --track, --no-track, or --no-guess was specified > > # if so, disable DWIM mode > > - local track_opt="--track" only_local_ref=n > > if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] || > > [ -n "$(__git_find_on_cmdline "--track --no-track --no-guess")" ]; then > > track_opt='' > > diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh > > index a134a8791076..9d02de167219 100755 > > --- a/t/t9902-completion.sh > > +++ b/t/t9902-completion.sh > > @@ -1351,6 +1351,13 @@ test_expect_failure 'git switch - with -C and --no-track, complete all reference > > EOF > > ' > > > > +# TODO: completion does not yet recognize --orphan > > +test_expect_failure 'git switch - with --orphan, do not complete anything' ' > > + test_completion "git switch --orphan " <<-\EOF > > + > > + EOF > > +' > > + > > I am getting "TODO passed" at 7276ffe0 (completion: add test showing > subpar completion for git switch --orphan, 2020-04-24), which hasn't > hit 'next' yet. > > Perhaps we got some rebase gotcha here? > Hmm.. Yea, I think there is a problem. Originally I had one commit which added the test case for --orphan and I fixed it later, but I rebased things so it was one commit. I probably just forgot to update the tests. Thanks, Jake > > test_expect_success 'teardown after ref completion' ' > > git branch -d matching-branch && > > git tag -d matching-tag &&
The proposed SQUASH you have in gitster/jk/complete-git-switch is correct. The commit message body is correct, but the title could be reworded to "completion: stop completing refs for git switch --orphan" I can send a v2 if that would be helpful, and I've got it fixed up locally if other review increases the need for a new spin. Thanks, Jake On Mon, Apr 27, 2020 at 4:34 PM Junio C Hamano <gitster@pobox.com> wrote: > > Jacob Keller <jacob.e.keller@intel.com> writes: > > > From: Jacob Keller <jacob.keller@gmail.com> > > > > git switch with the --orphan option is used to create a new branch that > > is not connected to any history and is instead based on the empty tree. > > > > It does not make sense for completion to return anything in this case, > > because there is nothing to complete. Check for --orphan, and if it's > > found, immediately return from _git_switch() without completing > > anything. > > > > Add a test case which documents this expected behavior. > > > > Signed-off-by: Jacob Keller <jacob.keller@gmail.com> > > --- > > contrib/completion/git-completion.bash | 11 ++++++++++- > > t/t9902-completion.sh | 7 +++++++ > > 2 files changed, 17 insertions(+), 1 deletion(-) > > > > diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash > > index c21786f2fd00..08d3406cf3e4 100644 > > --- a/contrib/completion/git-completion.bash > > +++ b/contrib/completion/git-completion.bash > > @@ -2223,9 +2223,18 @@ _git_switch () > > __gitcomp_builtin switch > > ;; > > *) > > + local track_opt="--track" only_local_ref=n > > + > > + # --orphan is used to create a branch disconnected from the > > + # current history, based on the empty tree. Since the only > > + # option required is the branch name, it doesn't make sense to > > + # complete anything here. > > + if [ -n "$(__git_find_on_cmdline "--orphan")" ]; then > > + return > > + fi > > + > > # check if --track, --no-track, or --no-guess was specified > > # if so, disable DWIM mode > > - local track_opt="--track" only_local_ref=n > > if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] || > > [ -n "$(__git_find_on_cmdline "--track --no-track --no-guess")" ]; then > > track_opt='' > > diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh > > index a134a8791076..9d02de167219 100755 > > --- a/t/t9902-completion.sh > > +++ b/t/t9902-completion.sh > > @@ -1351,6 +1351,13 @@ test_expect_failure 'git switch - with -C and --no-track, complete all reference > > EOF > > ' > > > > +# TODO: completion does not yet recognize --orphan > > +test_expect_failure 'git switch - with --orphan, do not complete anything' ' > > + test_completion "git switch --orphan " <<-\EOF > > + > > + EOF > > +' > > + > > I am getting "TODO passed" at 7276ffe0 (completion: add test showing > subpar completion for git switch --orphan, 2020-04-24), which hasn't > hit 'next' yet. > > Perhaps we got some rebase gotcha here? > > > test_expect_success 'teardown after ref completion' ' > > git branch -d matching-branch && > > git tag -d matching-tag &&
Jacob Keller <jacob.keller@gmail.com> writes: > The proposed SQUASH you have in gitster/jk/complete-git-switch is > correct. The commit message body is correct, but the title could be > reworded to > > "completion: stop completing refs for git switch --orphan" > > I can send a v2 if that would be helpful, and I've got it fixed up > locally if other review increases the need for a new spin. Thnaks. In the meantime, what I have is attached (the test title, in addition to the commit title, has been updated). The same logic would apply to "git checkout -b <TAB>" (or "git switch -c <TAB>") as this change: these are meant to create a new branch so you do not want to offer an existing branch name. I have a mixed feelings about that reasoning, though. I understand that not offering any existing branch name would avoid offering a branch name that would cause an error message from the command, which at a first glance feels like a nice help to the user, but I am not sure if it is really helping. When you are on jk/complete-switch branch to work on this topic, you may want to keep the current state of the branch and use a "v2" branch to play around (running "rebase -i" etc.), for which the way I would hope to work would be: git checkout -b jk/comp<TAB> that would complete to an existing branch git checkout -b jk/complete-switch and then I can just type "-v2<Enter>" (or "<BackSpace>-v2<Enter>" to remove the inter-word space completion adds?) after that. After all, "git checkout -b jk/complete-switch" in that scenario would error out by saying that you already use that name, which is a good enough protection. And that same "is this really helping?" reasoning applies equally to the "--orphan" option. I dunno. -- >8 -- From: Jacob Keller <jacob.keller@gmail.com> Date: Fri, 24 Apr 2020 19:20:38 -0700 Subject: [PATCH] completion: stop completing refs for git switch --orphan git switch with the --orphan option is used to create a new branch that is not connected to any history and is instead based on the empty tree. It does not make sense for completion to return anything in this case, because there is nothing to complete. Check for --orphan, and if it's found, immediately return from _git_switch() without completing anything. Add a test case which documents this expected behavior. Signed-off-by: Jacob Keller <jacob.keller@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> --- contrib/completion/git-completion.bash | 11 ++++++++++- t/t9902-completion.sh | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index c21786f2fd..08d3406cf3 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2223,9 +2223,18 @@ _git_switch () __gitcomp_builtin switch ;; *) + local track_opt="--track" only_local_ref=n + + # --orphan is used to create a branch disconnected from the + # current history, based on the empty tree. Since the only + # option required is the branch name, it doesn't make sense to + # complete anything here. + if [ -n "$(__git_find_on_cmdline "--orphan")" ]; then + return + fi + # check if --track, --no-track, or --no-guess was specified # if so, disable DWIM mode - local track_opt="--track" only_local_ref=n if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] || [ -n "$(__git_find_on_cmdline "--track --no-track --no-guess")" ]; then track_opt='' diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index a134a87910..7e4dd8e722 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -1351,6 +1351,12 @@ test_expect_failure 'git switch - with -C and --no-track, complete all reference EOF ' +test_expect_success 'git switch --orphan completes no references' ' + test_completion "git switch --orphan " <<-\EOF + + EOF +' + test_expect_success 'teardown after ref completion' ' git branch -d matching-branch && git tag -d matching-tag &&
On Tue, Apr 28, 2020 at 9:24 AM Junio C Hamano <gitster@pobox.com> wrote: > > Jacob Keller <jacob.keller@gmail.com> writes: > > > The proposed SQUASH you have in gitster/jk/complete-git-switch is > > correct. The commit message body is correct, but the title could be > > reworded to > > > > "completion: stop completing refs for git switch --orphan" > > > > I can send a v2 if that would be helpful, and I've got it fixed up > > locally if other review increases the need for a new spin. > > Thnaks. In the meantime, what I have is attached (the test title, > in addition to the commit title, has been updated). > > The same logic would apply to "git checkout -b <TAB>" (or "git > switch -c <TAB>") as this change: these are meant to create a new > branch so you do not want to offer an existing branch name. > While true, you may optionally have a 2nd argument which provides a start point that can be an arbitrary reference. > I have a mixed feelings about that reasoning, though. I understand > that not offering any existing branch name would avoid offering a > branch name that would cause an error message from the command, > which at a first glance feels like a nice help to the user, but I am > not sure if it is really helping. > > When you are on jk/complete-switch branch to work on this topic, you > may want to keep the current state of the branch and use a "v2" > branch to play around (running "rebase -i" etc.), for which the way > I would hope to work would be: > > git checkout -b jk/comp<TAB> > > that would complete to an existing branch > > git checkout -b jk/complete-switch > Hmm.. Yes this would be useful. > and then I can just type "-v2<Enter>" (or "<BackSpace>-v2<Enter>" to > remove the inter-word space completion adds?) after that. After > all, "git checkout -b jk/complete-switch" in that scenario would > error out by saying that you already use that name, which is a good > enough protection. > > And that same "is this really helping?" reasoning applies equally to > the "--orphan" option. > > I dunno. > Fair enough, new branches based on previous branches makes sense. Thanks, Jake > -- >8 -- > From: Jacob Keller <jacob.keller@gmail.com> > Date: Fri, 24 Apr 2020 19:20:38 -0700 > Subject: [PATCH] completion: stop completing refs for git switch --orphan > > git switch with the --orphan option is used to create a new branch that > is not connected to any history and is instead based on the empty tree. > > It does not make sense for completion to return anything in this case, > because there is nothing to complete. Check for --orphan, and if it's > found, immediately return from _git_switch() without completing > anything. > > Add a test case which documents this expected behavior. > > Signed-off-by: Jacob Keller <jacob.keller@gmail.com> > Signed-off-by: Junio C Hamano <gitster@pobox.com> > --- > contrib/completion/git-completion.bash | 11 ++++++++++- > t/t9902-completion.sh | 6 ++++++ > 2 files changed, 16 insertions(+), 1 deletion(-) > > diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash > index c21786f2fd..08d3406cf3 100644 > --- a/contrib/completion/git-completion.bash > +++ b/contrib/completion/git-completion.bash > @@ -2223,9 +2223,18 @@ _git_switch () > __gitcomp_builtin switch > ;; > *) > + local track_opt="--track" only_local_ref=n > + > + # --orphan is used to create a branch disconnected from the > + # current history, based on the empty tree. Since the only > + # option required is the branch name, it doesn't make sense to > + # complete anything here. > + if [ -n "$(__git_find_on_cmdline "--orphan")" ]; then > + return > + fi > + > # check if --track, --no-track, or --no-guess was specified > # if so, disable DWIM mode > - local track_opt="--track" only_local_ref=n > if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] || > [ -n "$(__git_find_on_cmdline "--track --no-track --no-guess")" ]; then > track_opt='' > diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh > index a134a87910..7e4dd8e722 100755 > --- a/t/t9902-completion.sh > +++ b/t/t9902-completion.sh > @@ -1351,6 +1351,12 @@ test_expect_failure 'git switch - with -C and --no-track, complete all reference > EOF > ' > > +test_expect_success 'git switch --orphan completes no references' ' > + test_completion "git switch --orphan " <<-\EOF > + > + EOF > +' > + > test_expect_success 'teardown after ref completion' ' > git branch -d matching-branch && > git tag -d matching-tag && > -- > 2.26.2-266-ge870325ee8 >
Jacob Keller <jacob.keller@gmail.com> writes: >> And that same "is this really helping?" reasoning applies equally to >> the "--orphan" option. >> >> I dunno. >> > > Fair enough, new branches based on previous branches makes sense. I actually do not have a strong opinion either way. I just wanted to say that it would be good to make it consistent across "checkout -b", "switch -c" and "checkout/switch --orphan". It would be nice if "checkout -B" and "switch -C" pair offered existing branches, as the intention of using the capital letter is clear---the user wants to overwrite an existing one. On the other hand, I am OK if "checkout -b", "switch -c" and "--orphan" offered either: (1) nothing, as your patch does, or (2) all branches, except for the currently checked out one. It would be preferrable if they did the same thing. Thanks.
On Tue, Apr 28, 2020 at 11:10 AM Junio C Hamano <gitster@pobox.com> wrote: > > Jacob Keller <jacob.keller@gmail.com> writes: > > >> And that same "is this really helping?" reasoning applies equally to > >> the "--orphan" option. > >> > >> I dunno. > >> > > > > Fair enough, new branches based on previous branches makes sense. > > I actually do not have a strong opinion either way. I just wanted > to say that it would be good to make it consistent across "checkout > -b", "switch -c" and "checkout/switch --orphan". > > It would be nice if "checkout -B" and "switch -C" pair offered > existing branches, as the intention of using the capital letter is > clear---the user wants to overwrite an existing one. > > On the other hand, I am OK if "checkout -b", "switch -c" and > "--orphan" offered either: > > (1) nothing, as your patch does, or > > (2) all branches, except for the currently checked out one. Why reject the currently checked out one? If the premise is: "use a current branch to build a new branch name", I don't see a reason to restrict including the current branch here as well. > > It would be preferrable if they did the same thing. > > Thanks. > The problem I see, is that regardless, I would like to see the following: git switch -c new-branch-name <SPACE><TAB> complete all references for the starting point. With this series, that's handled by just checking for "-c/-C" on the command line and enabling all references. There's no positional checks done, so every word can complete to a reference. I don't know offhand how to add completion which depends on the position of the word we're completing, so I'd have to investigate how to make that happen. Thanks, Jake
Jacob Keller <jacob.keller@gmail.com> writes: >> On the other hand, I am OK if "checkout -b", "switch -c" and >> "--orphan" offered either: >> >> (1) nothing, as your patch does, or >> >> (2) all branches, except for the currently checked out one. > > Why reject the currently checked out one? If the premise is: "use a > current branch to build a new branch name", I don't see a reason to > restrict including the current branch here as well. Yeah, "(3) all branches, without any exception" makes sense too. >> It would be preferrable if they did the same thing. >> >> Thanks. > The problem I see, is that regardless, I would like to see the following: > > git switch -c new-branch-name <SPACE><TAB> > > complete all references for the starting point. Makes sense. The starting point could be any branch or even a tag. > With this series, that's handled by just checking for "-c/-C" on the > command line and enabling all references. There's no positional checks > done, so every word can complete to a reference. > > I don't know offhand how to add completion which depends on the > position of the word we're completing, so I'd have to investigate how > to make that happen. I see. Even though I say "(3) all branches" is a reasonable behaviour, too, if the starting point has to be more (i.e. including tags), that would not help the issue you have here. It may not be too bad if we offered all refs (including tags, which may not be a good idea) in that case. I dunno. Thanks.
On Tue, Apr 28, 2020 at 12:16 PM Junio C Hamano <gitster@pobox.com> wrote: > > Jacob Keller <jacob.keller@gmail.com> writes: > > With this series, that's handled by just checking for "-c/-C" on the > > command line and enabling all references. There's no positional checks > > done, so every word can complete to a reference. > > > > I don't know offhand how to add completion which depends on the > > position of the word we're completing, so I'd have to investigate how > > to make that happen. > > I see. Even though I say "(3) all branches" is a reasonable > behaviour, too, if the starting point has to be more (i.e. including > tags), that would not help the issue you have here. It may not be > too bad if we offered all refs (including tags, which may not be a > good idea) in that case. I dunno. > > Thanks. > Basically, when creating a branch, you often do "git switch -c branch-name start-point" branch-name would be the new branch name you want, and I think we should complete local branches for this, but start-point can be any reference, i.e. a tag, a local branch, or a remote reference. I assumed completion would be most useful to complete the start-point, and so I opted to lean towards fixing completion for -c/-C to complete all references. However, I don't think the branch name should necessarily complete from all references and it would make sense to complete that portion only by local branch names. I'm just not sure how best to implement that in our completion logic, and I would rather ensure that start-point completes properly, if we have to choose. Thanks, Jake
Jacob Keller <jacob.keller@gmail.com> writes: > I assumed completion would be most useful to complete the start-point, > and so I opted to lean towards fixing completion for -c/-C to complete > all references. However, I don't think the branch name should > necessarily complete from all references and it would make sense to > complete that portion only by local branch names. > > I'm just not sure how best to implement that in our completion logic, > and I would rather ensure that start-point completes properly, if we > have to choose. Sure. What I was saying that if it is easier to implement by completing both new branch name and starting point from the same set, you could choose to include both branches and tags, and your "excuse" for choosing that design could be that a user who wants to fix something in 2.26 release may want the completion and typing progression go like so: $ git switch -c v2.2<TAB> ... offers v2.20, v2.21, ..., v2.26 as candidates ... complete to v2.26 and type "-frotz-fix" $ git switch -c v2.26-frotz-fix $ git switch -c v2.26-frotz-fix v2.2<TAB> ... again offers v2.20, v2.21, ..., v2.26 ;-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index c21786f2fd00..08d3406cf3e4 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2223,9 +2223,18 @@ _git_switch () __gitcomp_builtin switch ;; *) + local track_opt="--track" only_local_ref=n + + # --orphan is used to create a branch disconnected from the + # current history, based on the empty tree. Since the only + # option required is the branch name, it doesn't make sense to + # complete anything here. + if [ -n "$(__git_find_on_cmdline "--orphan")" ]; then + return + fi + # check if --track, --no-track, or --no-guess was specified # if so, disable DWIM mode - local track_opt="--track" only_local_ref=n if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] || [ -n "$(__git_find_on_cmdline "--track --no-track --no-guess")" ]; then track_opt='' diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index a134a8791076..9d02de167219 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -1351,6 +1351,13 @@ test_expect_failure 'git switch - with -C and --no-track, complete all reference EOF ' +# TODO: completion does not yet recognize --orphan +test_expect_failure 'git switch - with --orphan, do not complete anything' ' + test_completion "git switch --orphan " <<-\EOF + + EOF +' + test_expect_success 'teardown after ref completion' ' git branch -d matching-branch && git tag -d matching-tag &&