Commit Graph

107 Commits

Author SHA1 Message Date
Andy Stewart
986228fa89 Handle invalid diff base 2023-11-10 11:21:27 +00:00
Andy Stewart
feffce19fc Handle file renames
See #872.
2023-11-09 12:16:26 +00:00
Nikita Kouevda
f7b97666ae Remove "file unknown in base" check
Instead of checking whether this file exists in `diff_base` and
returning early, we let `git show` fail, which still creates an empty
`from_file` for the subsequent `git diff` to use.

This mostly reverts 2ee95686c5, but we
keep the test case.
2023-09-01 13:10:30 -07:00
Nikita Kouevda
28d463f199 mv restore into gitgutter#utility#system 2023-08-31 07:50:14 -07:00
Adam Tao
883d60ec0e fix(diff): Wrong diff if dos format combines with noeol
If fileformat is dos and eol is not set, then a '\r' (but without '\n')
will be written to the last line of temporary buffer file, which will
confuse git and make git think all lines are modified. Fix it by adding
'r' to all lines except the last one if fileformat is dos and eol is not
set.

Suggested-by: Andy Stewart <boss@airbladesoftware.com>
Signed-off-by: Adam Tao <tcx4c70@gmail.com>
2023-06-16 09:44:05 +01:00
Andy Stewart
6ebc0fd233 Extract function to reduce duplication 2023-06-05 09:50:17 +01:00
Andy Stewart
4ec072df23 Enable text conversion in git-show
This tells git-show to output the smudged version of a file if a
clean/smudge filter is defined for it.  In turns this allows us to diff
the buffer contents (which is smudged) against the reference version.

However patches cannot be applied.

See the man pages for git-show and gitattributes for more information.

See #796, #435.
2023-06-02 09:59:24 +01:00
Andy Stewart
2ee95686c5 Handle file which does not exist in diff base
If g:gitgutter_diff_base has been set and the file being processed does
not exist in that branch/commit, ensure that every line is marked as
added - this is how git-diff behaves.

Fixes #855.
2023-04-27 16:16:54 +01:00
Andy Stewart
626541edeb Heeds git's "assume unchanged" bit
I.e. does not diff files which should be assumed unchanged.

See:

    git update-index --[no-]assume-unchanged -- <file>
    git ls-files -v

Closes #826.
2022-04-23 08:25:46 +01:00
Andy Stewart
1283ec1670 Make error message useful 2021-02-22 14:15:46 +00:00
Andy Stewart
dfe55e2b92 Recreate temp directory if it gets deleted
Vim does not check the existence of its temp directory when generating
file names with tempname().  Therefore if, for some reason, the temp
directory gets deleted, Vim will continue to generate paths for file
names inside the directory.  Writes to these file paths will fail
(E482).

See #746, #433, #190, #147.
2020-11-25 12:42:00 +00:00
Andy Stewart
81963946ed Reuse tempfile base names
This reverts "Use fresh temp files for every diff" [1].  At the time I
did not realise that Vim never checks the existence of its temp
directory after creating it at startup; I thought that each call to
tempname() generated a fresh file on disk.  In fact tempname() simply
generates a string path.

Therefore there is no point calling tempname() for every diff.  Doing so
only serves to generate more files in the temp directory than necessary.

[1] dab840b153
2020-11-25 12:33:55 +00:00
Andy Stewart
e2c2edcd52 Remove duplicate args introduced in dc3c0dcd 2020-06-22 10:24:05 +01:00
Andy Stewart
70855aa93d Enable turning off limit on maximum number of signs
Setting the variable to a known value (-1) is neater than an arbitrary
high number.

See #681.
2020-04-27 10:02:03 +01:00
Andy Stewart
dab840b153 Use fresh temp files for every diff
Originally the plugin used fresh temp files for every diff.  But it
wrote to those files with `:write` which made Vim's buffer numbers
increase unnecessarily (see #297) so the plugin changed to reuse the
same temp files each time (see a871d857).

However this has the problem that after Vim has been open for a while,
e.g. a few days, the operating system can clean up the temp directory
holding those temp files.  The next time the plugin runs a diff, Vim
throws an error because it cannot write to the temp files because their
directory has disappeared (see #395, #433).

In the meantime the plugin changed how it writes the temp files to
use `writefile()` (see 4e911819).  This removed the problem of rapidly
increasing buffer numbers.

Now the buffer number problem has gone, the plugin can revert to using
fresh temp files each time.
2020-04-23 16:47:03 +01:00
Andy Stewart
2b62481d38 Only diff against parent commit in Fugitive revision buffers
Fixes #695.
2020-04-18 17:13:15 +01:00
Daniel Hahler
da2c785221 Set scriptencoding for file with utf8 BOM 2020-02-13 11:25:10 +00:00
Daniel Wyatt
2ef4f7e7b2 Use known shell for git_supports_command_line_config_override. 2020-01-22 09:00:31 +00:00
Andy Stewart
5c73edb3c2 Fix write_buffer() to not add extra line for dos fileformat 2019-10-15 10:14:10 +01:00
Andy Stewart
0bcd8c5b9c Update signs if linenrs highlighted
Fixes #656.
2019-09-30 13:20:43 +01:00
Andy Stewart
12bb0e9634 Do not write EOL after last line when no EOL present
See #650.
2019-09-19 12:20:42 +01:00
Andy Stewart
dc3c0dcd2a Ensure git calls always use configured args for git.
See #628.
2019-06-14 12:52:13 +01:00
Andy Stewart
064a3d6b10 Move #init_buffer() into #process_buffer(). 2019-05-29 14:36:53 +01: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
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
0597380f6b Prompt user to choose hunk when overlapping.
See #556.
2018-10-18 15:39: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
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
nagao_hiroki
3724e1c207 Add BOM support. 2018-03-26 22:12:46 +09: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
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
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
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
Andy Stewart
4e911819be Write buffer using writefile() instead of :write.
This is to avoid side effects caused by switching to the buffer to be
written and back again.

It also means that the plugin can process any buffer without having to
make it the current buffer.

Using the lower level writefile() function means we have to deal with
line endings.  It might also mean we have to deal with (file) encodings
but I hope not...

See #463, #466.
2018-02-13 10:22:36 +00:00
Andy Stewart
7f14cd142c Pass bufnr into warn_once function.
Fixes #465.
2018-02-13 09:32:38 +00:00
Andy Stewart
d137753182 Handle &write option being off (e.g. vim -m FILE).
See #407.
2018-02-12 16:19:01 +00:00
Andy Stewart
8da5b64868 Avoid autocmds when switching buffers to write temp file. 2018-02-12 16:02:03 +00:00
Andy Stewart
3a052e4777 More idiomatic execute. 2018-02-12 15:52:34 +00:00