Commit Graph

43 Commits

Author SHA1 Message Date
Andy Stewart
933af37935 Replace v:t_string with backward-compatible equivalent.
v:t_string was introduced in Vim 7.4.2071.

Closes #464.
2018-02-13 09:37:45 +00:00
Andy Stewart
1452900ffd Check buffer is active before init. 2018-02-12 15:34:49 +00:00
Andy Stewart
5bfe5b9209 Big refactor.
- Hunk stage/undo/preview no longer saves the buffer.
- Hunk undo no longer makes locations go out of sync.
- Grep can be opted out of (grep output with ansi escapes is number one cause
  of issues).
- Replaced g:gitgutter_grep_command with g:gitgutter_grep.
- Always runs git-diff the same way instead of in two possible ways.
- Separated detection of git tracking from diffing.
- Simplified path handling.
- Removed support for xolox shell: Windows taskbar does not flash with async
  jobs.
- Removed g:gitgutter_{eager,realtime}.
- Simplified implementation generally.
2018-02-12 14:25:11 +00:00
Andy Stewart
14dd430533 DRY buffer local namespace prefix. 2017-02-22 10:51:12 +00:00
Andy Stewart
1bbf892eba Use custom functions for plugin buffer-local variables. 2017-02-22 10:43:52 +00:00
Andy Stewart
9639f28037 Prevent undo-hunk scrolling window.
The previous implementation assumed that CTRL-Y and CTRL-E could scroll
by negative counts, i.e. in the opposite direction.  It turns out they
cannot: they treat negative counts as positive ones and always scroll in
the same direction.

This meant that undoing a hunk in the top half of the screen caused the
screen to scroll.

Closes #394.
2016-12-16 10:36:30 +00:00
Thomas Larrieu
1742a8f568 Replace "normal" command with "normal!"
We do not want to use user defined mappings
2016-10-27 21:35:39 +02:00
Andy Stewart
b1734a3916 Remove unnecessary space concatenation. 2016-10-18 10:14:21 +01:00
Andy Stewart
e113f07d0b Avoid autocmd side-effects when jumping to/from preview window.
Fixes #379.
2016-10-18 10:12:30 +01:00
Andy Stewart
55b556f7a2 Dedup buffer lists to avoid unnecessary work. 2016-10-10 12:52:05 +01:00
Andy Stewart
b5f23e9867 Use known shell for hunk staging, previewing, undoing.
Forgot to do this in 377c71d.

Closes #352.
2016-06-27 10:55:26 +01:00
Andy Stewart
f8da1fd6db Preserve screen line position when undoing a hunk.
Closes #346.
2016-05-23 10:31:17 +01:00
Andy Stewart
f5a5234f22 Allow configuration of git executable. 2016-05-16 13:47:14 +01:00
Andy Stewart
ba6e104848 Always use bash on unix.
Vim is single-threaded so we can make life easier by using a known shell
and restoring the original one afterwards.
2016-05-16 12:00:06 +01:00
Andy Stewart
cae4f72aa1 Abort functions at first error. 2016-05-13 14:14:41 +01:00
Andy Stewart
264d7f3a66 Only use "<nomodeline>" when available. 2016-05-13 09:48:43 +01:00
Andy Stewart
ea5d4cbeaf Don't process modelines after triggering autocommand.
Closes #334.
2016-05-10 15:54:01 +01:00
Joel D. Elkins
27f99c4a4d Fire autocommand after processing buffer. 2016-05-06 16:26:24 +01:00
Andy Stewart
e607a997ce Asynchronous diffs in Vim. 2016-04-29 09:50:57 +01:00
Andy Stewart
4bed1da648 Add simple logging. 2016-04-25 13:19:50 +01:00
Andy Stewart
d282c33789 Fix new-line signs for untracked repo files with square brackets.
Before the plugin tries to diff a file, it checks whether git is
tracking the file.  If git isn't tracking the file, it stops there and
doesn't display any signs.  If git is tracking the file, the plugin
remembers so next time it can skip the check.

When I introduced asynchronous diffing for NeoVim (18b78361), I made a
refactoring mistake which caused the plugin on second and subsequent
runs [to always think git is tracking a file][1].

The non-realtime diffs – the ones you get when you save a buffer –
basically run `git diff FILE`.  With an untracked file git returns
nothing and exits successfully.  So although the plugin erroneously
thinks git is tracking the file, it gets an error-free, empty diff back
and so removes any and all signs.  Which means that the bug doesn't make
any difference.

However the realtime diffs write the buffer's contents to a temporary
file, and write the file as staged in the index to a temporary file,
then run `git diff FILE1 FILE2`.  To write the staged version of the
file we use `git show :FILE > TMPFILE`.

When `FILE` isn't known to git, `git show :FILE` exits with an error.
Unless, that is, [the filename contains square brackets and you're using
git v2.5.0+][2], in which case git exits successfully with empty output.

So if you're using git v2.5.0+, and you're editing an untracked file in
a repository, and the filename contains square brackets, the plugin will
think: git is tracking the file; the realtime diff is successful; the
file in the index is empty; so every line in the the working copy must
be an addition; hence a `+` sign on every line.

[1]: 18b7836168/autoload/gitgutter/diff.vim (L119-L121)
[2]: http://comments.gmane.org/gmane.comp.version-control.git/285686

Closes #325.
2016-04-22 15:04:32 +01:00
Andy Stewart
b3db866aab Use "undo" instead of "revert" for discarding a hunk.
"Undo" is a better name than "revert" because:

- "revert" sounds like it has something to do with `git-revert` but they
  are entirely different;
- "undo" is consistent with vim's "undo": discarding changes and going
  back to the original.

Maintain backwards compatibility and add deprecation warnings.

Closes #306.
2016-04-21 11:40:27 +01:00
Andy Stewart
f0e2cb5b4a Avoid unnecessary diff when adding/staging/reverting hunks. 2016-02-09 10:11:41 +00:00
Andy Stewart
7ef03a7b43 More semantic function argument name. 2016-02-09 10:11:41 +00:00
Andy Stewart
68715a1903 Tweak comments. 2016-02-09 10:11:41 +00:00
Andy Stewart
be55719488 Revert 0416f20. 2016-02-09 10:11:41 +00:00
Andy Stewart
18b7836168 Neovim: run diffs asynchronously. 2016-02-09 10:11:41 +00:00
Andy Stewart
0416f209d8 Avoid unnecessary diff. 2016-02-08 14:18:52 +00:00
Andy Stewart
3a810a9afc Make the 'exceeded max signs' warning less intrusive.
- Only show it once per buffer.
- Redraw before echo to avoid the hit-enter prompt.

See #259.
2016-01-13 16:05:18 +00:00
Andy Stewart
186dada663 Warn when cursor not in a hunk. 2015-03-05 12:19:02 +01:00
Andy Stewart
c6ed14c662 Finer granularity for staging/reverting hunks. 2015-03-05 11:09:18 +01:00
Andy Stewart
6b8e908cc9 Enable . command to work with staging/reverting hunks. 2015-01-14 10:40:43 +01:00
Lingnan Dai
25257c44e7 Dealt with the case where the preview window is used by another plugin 2015-01-07 16:55:25 +01:00
Andy Stewart
dfe985a1a6 Use buffer numbers instead of buffer names.
Also don't pass buffer number to functions when they can look it up
themselves.

Using buffer numbers also eliminates any ambiguity which might arise
from symbolic links, where you have potentially two names for a file.

Thanks to @Z1MM32M4N for work on this (see #209).
2014-11-14 12:55:40 +01:00
Andy Stewart
e5eb9e6ecf Fix staging of hunks coming after deleted lines.
Previously vim-gitgutter generated context-free patches and applied
those to the index.  However when staging a hunk situated after any
deleted lines, the line numbers on the patch were out by the number
of lines deleted, and without any context git would apply the patch
to the wrong part of the file in the index.

This commit ensure patches are generated with 1 line of context,
allowing git to adjust the line numbers appropriately and apply the
patch to the right location.

More lines of context would help git more to adjust line numbers; but
the more context we have the more we group together hunks we would
like to treat separately.
2014-10-16 11:50:20 +02:00
Andy Stewart
1e8201963c Ensure closing preview window deletes previewed buffer. 2014-09-23 10:03:14 +02:00
Andy Stewart
83ace2014a Suppress signs when there are more than 500. 2014-07-21 16:36:16 +02:00
Andy Stewart
fed2dbad34 Move every function into gitgutter namespace.
This makes profiling much easier.
2014-06-26 11:09:29 +02:00
Andy Stewart
a2aa2b1100 Avoid Windows command prompt popups when possible.
Before this commit some Windows users saw the command prompt pop
up briefly, and/or the taskbar flicker, every time the plugin ran.

Now the plugin will use xolox's vim-shell and vim-misc, if they are
available and we are on Windows, to execute external commands.  Xolox's
clever plugins avoid the command prompt popup and taskbar flicker.

Windows users with those plugins installed can opt out by setting a
variable in their vimrc.

Many thanks to @suxpert for the initial code.
2014-06-19 10:45:40 +02:00
Andy Stewart
ceeba75239 Fix independent toggling of signs in sign column and line highlights.
Note that line highlighting requires signs to be placed (because the
line highlight is simply an attribute of a sign).  If the user doesn't
want to see signs in the sign column, but does want line highlighting,
then we make the signs in the sign column invisible.

If neither the signs in the sign column nor the line highlights are
needed (presumably the user just looks at the hunks stats) then we can
remove all signs, at which point Vim removes the sign column...unless
the "sign column always" option is set.
2014-05-19 15:50:51 +02:00
Andy Stewart
a4347c57ea When disabling, disable across all buffers. 2014-04-14 15:24:25 +02:00
Andy Stewart
0ca3f7e3cd Add hunk previewing. 2014-03-18 13:50:22 +01:00
Andy Stewart
9c66906d56 Move logic out of main plugin file. 2014-03-17 11:27:31 +01:00