[Bug]: unreliable `%(file)` variable
This %(file) seems to be set to a file when entering a file specific context (e.g.: moving to a file in the status view, moving to a file segment in the diff view, moving to a file in the blob view).
However, it won't be reset (to empty) when entering a non file context and is stuck to its previous value.
- Moving to a file section in the status view (e.g.: "Changes to be committed", "Untracked files", etc).
- Moving to a commit from the main view.
Because of that, it is impossible for external tools to know whether one must act on a single file or a set of files (full commit, all untracked files, etc.).
It is possible to workaround this for the status view section by using the %(status) variable (in a very hackish way). However, this variable is useless outside of the status view as it won't be updated either so it won't allow any workaround for per commit actions.
Here's couple of use cases.
Prerequisites
A mean to debug the variables.
I use something like:
bind generic B >sh -c 'echo "commit=[%(commit)],ref=[%(ref)],head=[%(head)],blob=[%(blob)],status=[%(status)],file=[%(file)],text=[%(text)]" | less'A repo with all kind of changes
A repo with the following kind of changes: "untracked", "unstaged", "staged" and "commited".
Use case 1
Enter the main view (
$tig)Go to the "Untracked changes" entry
commit=[0000000000000000000000000000000000000000],ref=[HEAD],head=[HEAD],blob=[],status=[Untracked file],file=[],text=[]`Hit
sto enter the status viewMove down to select a file entry
Hit
qto quit the status view and return to the main view Cursor is still on "Untracked changes", however itsfileis stuck to the file selected it the status view.commit=[0000000000000000000000000000000000000000],ref=[HEAD],head=[HEAD],blob=[],status=[Untracked file ],file=[my/file.ext],text=[]I would have expected for
fileto be empty as it was when I entered the main view.See also that
statusgained a trailing space character.
Use case 2
Enter the main view (
$tig)Go to the an actual commit.
commit=[a0d59c4e549d08f18544abcdd85c8affa0646e33],ref=[HEAD],head=[HEAD],blob=[],status=[Staged changes],file=[],text=[]Hit
dto enter the diff viewcommit=[a0d59c4e549d08f18544abcdd85c8affa0646e33],ref=[HEAD],head=[HEAD],blob=[],status=[Untracked file ],file=[],text=[commit a0d59c4e549d08f18544abcdd85c8affa0646e33]Note that
fileis empty as expected. Note also this oddstatusvalue (which also has a trailing white-space).Move your cursor down to a line that belong to a file in the diff
commit=[a0d59c4e549d08f18544abcdd85c8affa0646e33],ref=[HEAD],head=[HEAD],blob=[],status=[Untracked file ],file=[my/file.ext],text=[ my/file.ext | 2 --]Move back to the first line of the diff (file agnostic)
commit=[a0d59c4e549d08f18544abcdd85c8affa0646e33],ref=[HEAD],head=[HEAD],blob=[],status=[Untracked file ],file=[my/file.ext],text=[ my/file.ext | 2 --]See how
fileis still stuck to the file instead of being reset.Hit
qto quit the diff view and return to the main viewcommit=[a0d59c4e549d08f18544abcdd85c8affa0646e33],ref=[HEAD],head=[HEAD],blob=[],status=[Untracked file ],file=[my/file.ext],text=[commit a0d59c4e549d08f18544abcdd85c8affa0646e33]See how
filestill refer to the file we had when in the diff view instead of being reset as expected.See also
statusstill stuck to what it was in the diff view instead of having the same value it had originally.
Use case X
There are many more instances of this problem.
Source: jonas/tig