tpope / vim-fugitive

fugitive.vim: A Git wrapper so awesome, it should be illegal
https://www.vim.org/scripts/script.php?script_id=2975
20.03k stars 1.01k forks source link

Inline command substitution #2319

Closed nirmalnirav closed 2 months ago

nirmalnirav commented 4 months ago

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

Problem Statement

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

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 commented 3 months ago

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 commented 3 months ago

Hello @cjrh , it works! Thanks for the hint. :+1: 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 commented 3 months ago

It's just concatenation, no big mystery 😄

On Thu, 1 Aug 2024, 4:31 pm nirmalnirav, @.***> wrote:

Hello @cjrh https://github.com/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!

— Reply to this email directly, view it on GitHub https://github.com/tpope/vim-fugitive/issues/2319#issuecomment-2263227621, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADVJC234AZWLWIY2LMSLCDZPJBE5AVCNFSM6AAAAABKMXDTI2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENRTGIZDONRSGE . You are receiving this because you were mentioned.Message ID: @.***>

tpope commented 3 months ago

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 commented 2 months ago

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

cjrh commented 2 months ago

@nirmalnirav You can close it yourself 😄