Option to show diff against older commit
- Dominant language
- Vim Script
- Stars
- 2.7k
- Forks
- 113
- PR merge metrics
- No merged PRs in 30d
Description
Thanks for the great plugin—I switched from vim-gitgutter and am very happy I did.
However, there's one gitgutter feature I missed so much that I needed to re-implement it in my .vimrc—the ability to diff against a commit other than `HEAD`. I realize something similar was discussed in #232; if you are committed to not including this feature, that's no problem—I've already handled my use case. But I thought I'd take a minute to make the argument in case you are willing to support the feature. What I have to say will be Git-specific, since that's the VCS that I know.
Here's the use-case. As you doubtless know, a very common work-flow (especially in open-source projects), is for someone to submit a PR and then receive comments/change requests on that PR. When reviewing those comments, it's very helpful for the submitter to see the changes that they made in the PR—that is, to diff the file against `HEAD~` or `HEAD~2`. It's much less useful to review the changes against `HEAD`, since that's the version that was just submitted; necessarily, it doesn't have any changes.
Here's how I addressed the issue in my .vimrc:
```vimscript
let g:target_commit = 0
command! SignifyOlder call ChangeTargetGitCommit('older')
command! SignifyNewer call ChangeTargetGitCommit('younger')
function ChangeTargetGitCommit(older_or_younger)
if a:older_or_younger ==# 'older'
let g:target_commit += 1
elseif g:target_commit==#0
echom 'No timetravel! Cannot diff against HEAD~-1'
return
else
let g:target_commit -= 1
endif
let l:git_command = printf('%s%d%s', 'git diff --no-color --no-ext-diff -U0 HEAD~', g:target_commit, ' -- %f')
let g:signify_vcs_cmds = {
\ 'git': l:git_command,
\ 'hg': 'hg diff --config extensions.color=! --config defaults.diff= --nodates -U0 -- %f',
\ 'svn': 'svn diff --diff-cmd %d -x -U0 -- %f',
\ 'bzr': 'bzr diff --using %d --diff-options=-U0 -- %f',
\ 'darcs': 'darcs diff --no-pause-for-gui --diff-command="%d -U0 %1 %2" -- %f',
\ 'fossil': 'fossil diff --unified -c 0 -- %f',
\ 'cvs': 'cvs diff -U0 -- %f',
\ 'rcs': 'rcsdiff -U0 %f 2>%n',
\ 'accurev': 'accurev diff %f -- -U0',
\ 'perforce': 'p4 info '. sy#util#shell_redirect('%n') . (has('win32') ? ' &&' : ' && env P4DIFF= P4COLORS=') .' p4 diff -du0 %f',
\ 'tfs': 'tf diff -version:W -noprompt %f',
\ }
let l:output_msg = printf('%s%d', 'Now diffing against HEAD~', g:target_commit)
echom l:output_msg
endfunction
```
Of course, the full version would have to be significantly expanded to address the other VCSs, but that might provide a flavor of a solution.
As I said, I've already addressed my use-case, but I thought I'd add my $0.02 about what features would be useful.
Thanks again for the great plugin.
Contributor guide
Research direction
Review the discussion in #232 and the plugin's existing VCS command configuration, using the SignifyOlder/SignifyNewer and g:target_commit example as the starting point. Confirm how a selected Git base such as HEAD~ or HEAD~2 should be exposed and how other VCSs are handled; done means the requested older-commit diff works without disrupting existing VCS behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, vim
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100