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

Option to show diff against older commit #284

Open
codesections opened this issue Feb 9, 2019 · 2 comments
Open

Option to show diff against older commit #284

codesections opened this issue Feb 9, 2019 · 2 comments

Comments

@codesections
Copy link

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:

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.

@mhinz
Copy link
Owner

mhinz commented Feb 10, 2019

Thanks for the request!

This needs a lot of work and especially testing done to make sure that the experience is the same for all supported VCS. I'm not refusing the general idea, though.

But it probably won't happen anytime soon, since there are other things I want to improve first (like updating signs without relying on the current state of the buffer being written to disk, so that g:signify_realtime can be enabled by default).

@ezzieyguywuf
Copy link

Hah, I should have checked here first. See #394 which can maybe be used as a starting point to integrate this feature.

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

No branches or pull requests

3 participants