holygeek / git-number

Use numbers for dealing with files in git
ISC License
281 stars 25 forks source link

Any args given after `--' are passed to the underlying command verbatim. #46

Closed KES777 closed 1 year ago

KES777 commented 1 year ago

How to reproduce:

$ alias gl
alias gl='f(){ gn log -w -b -p --ignore-blank-lines --full-history $@; unset -f f; }; f'

$ gl 9ce3e165f284d55503eff9b627ef3723854c53bb^ -- lib/Invoice/Schema/Result/Company.pm
git log -w -b -p --ignore-blank-lines --full-history 9ce3e165f284d55503eff9b627ef3723854c53bb^ lib/Invoice/Schema/Result/Company.pm
fatal: ambiguous argument 'lib/Invoice/Schema/Result/Company.pm': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

It seems -- is lost. I expect command to look like: git log -w -b -p --ignore-blank-lines --full-history 9ce3e165f284d55503eff9b627ef3723854c53bb^ -- lib/Invoice/Schema/Result/Company.pm

Another issue here it seems that it is not possible to pass the number for lib/Invoice/Schema/Result/Company.pm file, eg git log -w -b -p --ignore-blank-lines --full-history 9ce3e165f284d55503eff9b627ef3723854c53bb^ -- 7

I need to pass file after -- because this file was deleted and does not exists at current working directory, so I need to pass its name after --.

holygeek commented 1 year ago

Thanks for reporting this. I pushed a fix (f7pd393) for passing down -- to the command to be ran.

As for the second issue it's not possible to expand numbers after -- as those will be passed intact to the command. What you can do instead is use git-list to expand it, e.g.: gl -- $(git-list 7)

KES777 commented 1 year ago

How about gl --- 7 feature?

Triple - will mean to process string after --- and pass result as -- lib/Invoice/Schema/Result/Company.pm.

This will save a lot of typing. For comparison:

gl --- 7 xx 9
gl -- $(git-list 7) xx $(git-list 9)
holygeek commented 1 year ago

Interesting idea! I'm not opposed to that. It will be a bit tricky to implement though.

holygeek commented 1 year ago

Something like this would work perhaps:

$ git diff git-number
diff --git git-number git-number
index 43f6637..f00e652 100755
--- git-number
+++ git-number
@@ -140,6 +140,11 @@ while (scalar @ARGV) {
         last;
     }

+    if ($arg eq '---') {
+        push(@args, '--');
+        next;
+    }
+
     if ( $arg =~ m/^[0-9][0-9]*$/ ) {
         push @args, split("\n", `git-list $arg`);
         $converted=1;

Just need some unit tests and it should be good, I think.

KES777 commented 1 year ago

Checked new version. Works fine. Thank you very much for fixes.