Re: [PATCH] completion: complete paths for git send-email
Junio C Hamano <[email protected]>
| Newsgroups | org.kernel.vger.git,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
"Yury Norov (NVIDIA)" <[email protected]> writes: > From: Yury Norov <[email protected]> > > git send-email accepts either revisions or paths to patch files, but its > Bash completion only offers revisions. This prevents patch files from > being completed. It can also make a prefix such as "0" expand to an > unrelated hexadecimal ref even when matching 0001-*.patch files exist. > > In my Linux tree, an attempt to autocomplete the standard-named patch > brings a random hashtag: > > $ ls 0* > 0001-bitmap-drop-bitmap_next_set_region.patch > $ git send-email 0<Tab> > $ git send-email 05c69d298c96703741cac9a5cbbf6c53bd55a6e2 Wow. Even though I use nothing but 'git send-email' when sending my own patches, I have never noticed this behavior. I guess that is primarily because I only use the command via my own wrapper script, so the usual bash completion kicks in only for filenames in my workflow. Since I store my patches two levels deep in my working tree (for example, '+outgo/topic/0000-cover-letter.txt'), I suspect that even if I got rid of my wrapper, I would not suffer from this issue. An attempt to run 'git send-email +outgo/contrib-doc/0<TAB>' expanding the trailing '0' into a hexadecimal object name would indeed be quite annoying. Good find. > Introduce an append variant of __gitcomp_file() and use it to add > filesystem candidates after the existing revision candidates. Keep the > latter because revisions remain valid send-email arguments. OK. I will need help from those who are more familiar with our completion code than I am to properly assess this change. Any assistance in reviewing this would be appreciated. > diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh > index 55dc9eabf..e87827f21 100755 > --- a/t/t9902-completion.sh > +++ b/t/t9902-completion.sh > @@ -2777,7 +2777,17 @@ test_expect_success PERL 'send-email' ' > test_completion "git send-email --val" <<-\EOF && > --validate Z > EOF > - test_completion "git send-email ma" "main " > + test_completion "git send-email ma" "main " && > + > + git tag 05c69d298c96703741cac9a5cbbf6c53bd55a6e2 && > + test_when_finished "git tag -d 05c69d298c96703741cac9a5cbbf6c53bd55a6e2 && > + rm -f 0001-example.patch 0002-example.patch" && If the initial 'git tag' fails, 'test_when_finished' is never registered, and we end up failing to remove the '000?-example.patch' files. The usual way to write this is: - set up 'test_when_finished' with a body that is written to succeed even if the clean-up target is not present (your '-f' in 'rm -f' is good, as it prevents 'rm' from failing even if '0001-example.patch' does not get created); then - write the test code that dirties the state (requiring clean-up) after registering the 'test_when_finished' handler. That is, "Prepare the clean-up first, and then you do not have to worry about making a mess." By the way, the use of a purely hexadecimal string as a tag or branch name is highly misleading. What happens if an object exists whose name is identical to that tag? Git offers ways to disambiguate if you really want to, but I do not see any reason for a sensible person or workflow to deliberately place oneself in a situation where such disambiguation becomes necessary. Of course, that is no excuse for the bug. Our completion script should not misbehave, even when confronted with a workflow that uses funny-looking tags.