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

%(head) is empty when starting tig with branch name given #1366

Open
ds82 opened this issue Feb 20, 2025 · 3 comments
Open

%(head) is empty when starting tig with branch name given #1366

ds82 opened this issue Feb 20, 2025 · 3 comments

Comments

@ds82
Copy link

ds82 commented Feb 20, 2025

I have this binding to start a code review in neovim directly from the selected commit in tig:

bind main v !>nvim +'DiffviewOpen %(commit)~1..%(head)' 

Thing is .. that only works if the branch I want to review is currently checked out or if I use tig -> view-refs, select the branch and commit and then use the keybind.

If I start tig with a branch directly, e.g. tig origin/some/branch and select a commit, the %(head) variable contains the wrong commit (the one of the currently checked out branch, not the branch I called tig with).

Edit: I also tried %(branch) and %(refname) but they wont work either.

@koutcher
Copy link
Collaborator

%(revargs) should do the job for your binding, but I agree it would be best to initialize %(head) from a revision in %(revargs) as it may also contain other revision arguments like --all.

@ds82
Copy link
Author

ds82 commented Feb 27, 2025

hmm ..

bind main V !echo "%(commit) %(head) %(revargs)"

results in the error Failed to format arguments

@koutcher
Copy link
Collaborator

koutcher commented Feb 27, 2025

bind main V !echo %(commit) %(head) %(revargs) works but your original binding will also fail with %(revargs) due to 's. No luck with current Tig version, the following patch initialises %(head) from command line arguments:

diff --git a/src/tig.c b/src/tig.c
index 1b115d23..5dcb461a 100644
--- a/src/tig.c
+++ b/src/tig.c
@@ -427,8 +427,10 @@ filter_options(const char *argv[], enum request request)
                                argv[flags_pos++] = argv[next++];
                else if (argv_parse_rev_flag(arg, NULL))
                        argv_append(&opt_rev_args, arg);
-               else
+               else {
                        argv[flags_pos++] = arg;
+                       string_copy_rev(argv_env.head, arg);
+               }
        }

        argv[flags_pos] = NULL;

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

2 participants