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.
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>
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.
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.
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.
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
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.
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.
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.
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.
Previously gitgutter could only diff the buffer against the index. This
change enables diffing against the working tree, which will be useful
for stashing.
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.
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.
- 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.