Commit Graph

184 Commits

Author SHA1 Message Date
Andy Stewart
8f6c4cb88c Minor refactor. 2019-01-15 11:40:04 +00:00
Andy Stewart
bf2a9ff4e8 Save and restore foldlevel. 2019-01-15 11:39:17 +00:00
Andy Stewart
714d468344 Enable unfolding 3 lines of context around each hunk. 2019-01-15 11:33:48 +00:00
Andy Stewart
ac787afa02 Add GitGutterFold command.
Closes #286, #571.
2019-01-14 11:48:24 +00:00
Andy Stewart
2dce8e032b Add commands to enable/disable/toggle GitGutter per buffer. 2019-01-08 12:47:10 +00:00
Andy Stewart
1d422b9f98 Revert to non-binary writefile() for writing buffer.
The previous commit switched use of writefile() to binary mode so that
we could prevent a newline being added to a completely empty buffer.
Evidently, however, binary mode has side effects (see #567) so this
commit returns to non-binary mode - with a simpler fix for completely
empty files.

Unfortunately this implementation does not work for noeol files - see
the failing test - because writefile() does not take account of
'nofixeol' (unlike :write).  This is suboptimal but acceptable because
noeol files are not be encountered often.

See #567.
2018-12-15 14:55:14 +00:00
Andy Stewart
5c636b128e Fix handling of buffer consisting only of a newline.
See #510.
2018-12-13 10:50:02 +00:00
Daniel Hahler
9a23a2f207 diff: fix handling of empty file
An empty, unchanged file was considered to be changed (a new line
added).
This patch fixes s:write_buffer to use binary mode with `writefile` to
not append a newline always, and does so manually for non-empty buffers,
according to &endofline, &binary and &fixendofline.

This is taken out of Neomake, and tested there in
https://github.com/neomake/neomake/blob/091d148b/tests/utils.vader#L713-L759.
2018-12-13 10:35:06 +00:00
Andy Stewart
c2651aefbd Do not pass a default value to getbufvar().
That was introduced in Vim 7.3.831 but there are a few Vims older than
that still around.

See:
af1e674155 (commitcomment-31431773)
2018-11-26 16:46:51 +00:00
Andy Stewart
208b439585 Vim: remove unreliable way of preventing close callback for unsuccessful job.
Until this commit the err callback closed the channel to prevent the close
callback from being invoked, because the close callback invoked the out
handler (which we don't want when the job was unsuccessful).

This mostly worked but if closing the channel took too long, which it
seemed it could when dealing with large files, the close callback could
be called in the meantime.

This commit removes the unreliable code.  The parent commit ensured that
the close callback only calls the out handler when the job succeeded, so
we no longer need to try to prevent the close callback from being
called.
2018-11-17 17:22:53 +00:00
Andy Stewart
da91d44889 Vim: only invoke async out handler when job succeeded.
This makes the plugin use Vim the same was as Neovim in terms of
invoking callback handlers.
2018-11-17 17:13:13 +00:00
Andy Stewart
32d53f134a Avoid race condition processing the same buffer twice, quickly.
The diffing part of the plugin diffs two files which are written afresh
each time.  When the same buffer was processed twice in quick
succession, the second process to write a file could write it before the
first process had finished reading it.  This manifested as the "from"
file being read as empty, causing diff to report that all the lines in
the file had been added.

This commit adds a counter to disambiguate successive temporary files.
2018-11-17 11:29:41 +00:00
Andy Stewart
947737c76f Handle non-ASCII paths.
This prevents git-ls-files from escaping "unusual" characters in
pathnames.  When this happened, gitgutter would feed the escaped name
back to git-show but git-show would not recognise it.

This commit makes git-ls-files use the -z option to output pathnames
verbatim.  These pathnames also become null terminated so we have to
ensure we remove the null terminator too.

Closes #562.
2018-11-17 11:24:36 +00:00
Andy Stewart
0597380f6b Prompt user to choose hunk when overlapping.
See #556.
2018-10-18 15:39:55 +01:00
Andy Stewart
4bd95abe6a Improve comment. 2018-10-18 15:39:47 +01:00
Andy Stewart
7267022d76 Fix nested array concatenation. 2018-10-18 15:15:29 +01:00
Andy Stewart
6f8acdcea1 Whitespace. 2018-10-18 09:48:57 +01:00
Andy Stewart
89c34f74cb Display unambiguous sign when hunks overlap.
See #556.
2018-10-18 09:45:55 +01:00
Andy Stewart
622193a625 Enable diffing against the working tree.
Previously gitgutter could only diff the buffer against the index.  This
change enables diffing against the working tree, which will be useful
for stashing.
2018-10-12 15:49:25 +01:00
Daniel Hahler
af1e674155 Fix gitgutter#utility#setbufvar for nonexistent buffers
Use a default with `getbufvar` to not get an empty string.

Fixes:

> Error detected while processing function <SNR>163_on_stderr_nvim[1]..<lambda>10[1]..gitgutter#utility#setbufvar:
> line    1:
> E712: Argument of get() must be a List or Dictionary

I can trigger it using https://github.com/AndrewRadev/linediff.vim when
closing the windows / the tab.
Likely triggered with/through Neomake.
2018-10-11 11:30:26 +01:00
Andy Stewart
d2d2da11c5 Add g:gitgutter_git_args for args to git when running git-diff.
See #541, #546.
2018-07-31 14:28:36 +01:00
Andy Stewart
d2f38f401a Revert "Explicitly tell git to diff outside any repo."
This reverts commit b4e43ae9e7.

It benefitted a small use case but causes problems for others.

See #541, #546.
2018-07-31 14:18:45 +01:00
Andy Stewart
b4e43ae9e7 Explicitly tell git to diff outside any repo.
Closes #541.
2018-07-27 12:49:14 +01:00
Andy Stewart
64663ab24f Handle buffers which no longer exist when callback executed.
Closes #509.
2018-07-04 08:43:58 +01:00
John Kurkowski
f363799550 Support files with a leading -
Git treats anything past the `--` as filenames.
2018-05-05 23:05:31 -07:00
Daniel Hahler
22c3fc0bf5 gitgutter#utility#setbufvar: ensure bufnr is a number with setbufvar
Otherwise you might get "E93: More than one match for X" if there is a
buffer with "X" in its name besides buffer number X.
2018-05-02 08:06:48 -07:00
Andy Stewart
5481318fc1 Prevent infinite loop when running non-async on Windows.
Closes #505.
2018-04-11 09:56:43 +01:00
nagao_hiroki
3724e1c207 Add BOM support. 2018-03-26 22:12:46 +09:00
Andy Stewart
37bdd03d17 Do not deactivate gitgutter when &diff is set.
In #303 there was a request to deactivate gitgutter when &diff is set,
although no reason was given initially.  Then it was reported that
gitgutter showed signs, in the wrong place, during Fugitive's Gdiff.

However I cannot reproduce signs showing in Gdiff's index buffer.  And
the signs in the working tree buffer are correct.

Furthermore the commit which deactivated gitgutter (85f6e136) had the
side-effect of breaking `:redir` and clearing Vim's startup message
(see #500).

Therefore since that change had no benefit, and a couple of drawbacks,
it makes sense to undo it.

Closes #500.
2018-03-16 18:49:22 +00:00
Andy Stewart
813723a195 Whitespace. 2018-03-14 14:40:14 +00:00
Andy Stewart
efd373d86d Move look-up out of loop. 2018-03-14 14:40:06 +00:00
Bakudankun
3b2461b2fb Fix wrong signs when &encoding and &fileencoding differ 2018-03-14 14:34:24 +00:00
Andy Stewart
2f736d58b4 Backward compatibility for nvim-0.1.7.
NeoVim 0.1.7 does not support the `function()` function accepting an
optional argument list.

Fixes #496.
2018-03-14 11:43:36 +00:00
Andy Stewart
380e7935b7 Make test flag more specific. 2018-03-08 11:47:08 +00:00
Chayoung You
538e07882a Handle files in different drive on Windows 2018-03-06 03:07:42 -08:00
Andy Stewart
b87aacbbfe Do not treat win32unix as Windows.
This reverts 16568f4815 which was, I believe now, mistaken.

See #471.
2018-03-06 10:55:47 +00:00
Andy Stewart
5db4a3a2a5 Make robust the replacement of temp file paths with actual paths.
The previous implementation meant the temp file paths were treated as
regular expressions, which was vulnerable to problems with backslashes
etc.

See #494.
2018-03-02 12:44:49 +00:00
Andy Stewart
fa85bd41d9 Pass filepath into s:fix_file_references() to make function pure. 2018-03-02 11:41:48 +00:00
Andy Stewart
05e538e553 Remove irrelevant comment. 2018-03-01 10:24:08 +00:00
Daniel Hahler
85d762fff6 Improve warning message for max-signs-exceeded 2018-03-01 10:11:03 +00:00
Daniel Hahler
41b951e64e Fix gitgutter#utility#warn_once: use echom
This a) logs the message to be seen in `:mess` and b) avoids the
hit-ENTER prompt (which is likely caused by the message not being
logged and Vim deciding that you need to see it then).

So a) fixes b).
2018-03-01 10:11:03 +00:00
Andy Stewart
0055e97bac Use '-c "core.safecrlf=false"' to avoid unhelpful line ending warnings.
See #486.
2018-02-28 19:17:31 +00:00
Andy Stewart
293b633d79 Add --no-pager to git-show and git-diff.
I needed these to get output from the commands on Windows.
2018-02-28 16:45:39 +00:00
Andy Stewart
e512d3a6fc Make the process_hunks() function public.
This is so other plugins, e.g. vim-signature, may use it.

Closes #489.
2018-02-26 08:58:27 +00:00
Andy Stewart
b27ee4d602 Rename variable for clarity. 2018-02-22 16:23:17 +00:00
Daniel Hahler
c325a8b6d3 s:fix_file_references: handle diff.mnemonicPrefix
An alternative would be to run `git` with no user config always, i.e.
setting `GIT_CONFIG_NOSYSTEM` and `HOME=/dev/null` (different for
Windows then) in its environment.  Maybe there's an easier way / single
option for this..
2018-02-22 09:49:31 +00:00
Daniel Hahler
4931dd1a82 Conditionally define s:vimdiff
This optimizes it a bit since the `exists()` is not called always.
2018-02-21 11:46:36 +00:00
Daniel Hahler
18f6d0ffe1 gitgutter#utility#setbufvar: skip unnecessary setbufvar
An existing dict gets returned by reference, so changing it does not
need a call to `setbufvar` afterwards.
2018-02-21 11:39:42 +00:00
Daniel Hahler
a046b5ace1 Improve GitGutter User autocommand: context/unsilent
This provides `g:gitgutter_hook_context` during the hook's execution and
removes the `:silent`, but uses `exists()` instead.

The bufnr might be necessary to know in the User autocommand, e.g. to
clear some cache.
Not using`:silent` is good practice in general to not hide (wanted)
output and errors etc.
2018-02-21 11:23:02 +00:00
Andy Stewart
d86ac1353f Avoid race conditions when processing multiple buffers asynchronously.
Fixes #472.
2018-02-19 12:56:22 +00:00