Skip to content
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

Inline command substitution #2319

Closed
nirmalnirav opened this issue Jul 5, 2024 · 6 comments
Closed

Inline command substitution #2319

nirmalnirav opened this issue Jul 5, 2024 · 6 comments

Comments

@nirmalnirav
Copy link

Respected Mr. Pope,
please accept my gratitude and then greetings. I am humbled that I have a chance to write you.

Problem Statement

  • On the command line it is possible to use the command substitution.
  • Error upon the command :G diff --stat $(G merge-base --fork-point main_branch)

Error

fatal: ambiguous argument '$(G': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

Explanation

  • We use BitBucket to collaborate at work. I want to avoid it and hence started looking for ways to work exclusive from terminal.
  • I came across a way to find the commit hash at which a feature_branch was created: git merge-base --fork-point main_branch.
  • Currently I would like to use that command and replace its output inline within another command: G diff --stat $(G some_command).
  • That way I can navigate to the file(s) of interest using the vim normal mode command gf from the file list.

Extension

If possible, please break the feature request in to smaller tasks along with a short pointer to the code section and assign them to me. I would gladly work on them and hence collaborate with you. I have never done any serious vim scripting and therefore would be a good learning experience.

Thank you for your time!

@cjrh
Copy link

cjrh commented Jul 30, 2024

An option is to build your own using execute. I'm also using merge-base in a similar way:

:execute 'Git diff ' . system('git merge-base --fork-point upstream/main')[0:-2]

The commit hash coming from merge-base has a trailing newline, which the [0:-2] removes.

@nirmalnirav
Copy link
Author

Hello @cjrh ,
it works! Thanks for the hint. 👍
I could not find the meaning of a single dot . between diff ' and system in the vim help. Could you please explain/ hint me to the meaning of the dot?
Thanks!

@cjrh
Copy link

cjrh commented Aug 2, 2024 via email

@tpope
Copy link
Owner

tpope commented Aug 2, 2024

Fugitive does provide an API for that system() call that's a bit more robust:

:execute 'Git diff ' . FugitiveExecute(['merge-base', '--fork-point', 'upstream/main']).stdout[0]

@nirmalnirav
Copy link
Author

Wonderful! Thanks for the comment! I would like to close this ticket as solved.

@cjrh
Copy link

cjrh commented Aug 12, 2024

@nirmalnirav You can close it yourself 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants