Commit Graph

854 Commits

Author SHA1 Message Date
Fred Hornsey
85ca3a0872 Use shellescape on paths in run_diff
In Neovim 0.11.1 within MSYS2 on Windows, gitgutter wasn't showing up.
After some flailing around, I found adding
`set shellcmdflag=-c shellxquote= shellxescape=`
[from here](https://github.com/neovim/neovim/issues/28384#issuecomment-2135921829),
got `:echo system('git --version')` working. The signs were still not
showing up, but there were files being dumped in my current working
directory that looked like corrupted Windows paths.

After using `let g:gitgutter_log=1` and looking at the log I found where
these temp files were made and I think I fixed it. I haven't tried the
non-msys2 Neovim (assuming that's different) or normal vim, but I
brought the change over and made sure it worked in Neovim on Linux.
2025-05-26 14:33:03 +01:00
Andy Stewart
a5ae0a5a18 Handle quickfix autocmd changing buffer
To keep things fast we turn off gitgutter in the current buffer during
quickfix commands, e.g. :vimgrep, and turn it back on afterwards.

However the user may have a quickfix autocmd which makes a different
buffer the current one, e.g. :cwindow. Previously this caused an error
because gitgutter expected the current buffer to remain current; now we
explicitly enable the original current buffer.

Fixes #904.
2025-05-05 15:15:44 +01:00
Andy Stewart
6620e5fbbe Document :write in preview window 2025-03-07 09:47:02 +00:00
Andy Stewart
33cb7744c3 Document re-preview moving into Nvim floating window
See #903.
2025-03-07 09:45:42 +00:00
Touko Hallasmaa
d3a9986fe8 Fix moving to floating window 2025-03-07 09:39:31 +00:00
Andy Stewart
7b0b5098e3 Fix async commands with Neovim on Windows
Closes #894.
2024-07-16 16:16:19 +01:00
Andy Stewart
bed580ab8b Use git -C instead of cd 2024-07-13 06:20:56 +01:00
Luke Davis
e801371917 Respect &foldopen during next/prev hunk jumps 2024-04-29 20:55:22 +01:00
Andy Stewart
67ef116100 Fix the fix for colons in basepath
Commit 84bc2d6 tried to handle basepath values where the path contained
colons (see #877).  However the fix had two (!) bugs.

- It used strridx() to find the colon separating the diffbase and the
  path; it should have used stridx() because the base comes first.
- It used substring indexes incorrectly: foo[0:-1] returns the whole of
  foo, not an empty string (:help exr-[:]).

Closes #878.
2024-01-05 12:43:02 +00:00
Andy Stewart
84bc2d68c0 Fix base_path() to handle filenames with colons
This bug was introduced when teaching gitgutter to handle file moves
in #872.

Fixes #877.
2024-01-03 16:06:27 +00:00
Andy Stewart
4b49965897 Warn user when unable to list renamed files 2023-12-07 13:56:55 +00:00
Andy Stewart
fe0e8a2630 Add comments 2023-11-11 10:56:40 +00:00
Andy Stewart
3b5acc05a1 Guard config flag in file moves check 2023-11-10 18:23:47 +00:00
Andy Stewart
1e7be38a3c Make command line config flag global 2023-11-10 18:19:48 +00:00
Andy Stewart
b9e9ad2ae2 Fix -c flag to apply to git command not diff subcommand
Fixes #874.
2023-11-10 18:09:44 +00:00
Andy Stewart
6efb835aa2 Suppress crlf warning when obtaining file moves
See comment above gitgutter#diff#run_diff() for rationale.
2023-11-10 15:55:55 +00:00
Andy Stewart
61f80c80ba Mention integration with fugitive's :0Gclog
I actually added this 3.5 years ago (0e509fb) but never updated the
readme.
2023-11-10 12:48:54 +00:00
Andy Stewart
6a95f1b57c Mention file moves in readme 2023-11-10 12:44:11 +00:00
Andy Stewart
c3b99e52f5 Add test for file moves
See #872.
2023-11-10 12:42:19 +00:00
Andy Stewart
de86ff5c03 Fix GitGutterDiffOrig to handle file moves
See #872.
2023-11-10 12:12:24 +00:00
Andy Stewart
952dbc34f7 Move base_path() to gitgutter#utility 2023-11-10 12:09:33 +00:00
Andy Stewart
4e262693a5 Handle file moves for quickfix
Do not assume the new name (`fnamer`) is the same length as the old
name (`fnamel`).

Also use the new name rather than the old name when populating the
quickfix list.

See #872.
2023-11-10 12:03:07 +00:00
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
Andy Stewart
744a0fcd9e Add test for not clobbering v:shell_error
See #869, #870.
2023-09-01 10:15:55 +01:00
Andy Stewart
101e9ca217 Fix typo in test 2023-09-01 10:05:31 +01:00
Nikita Kouevda
28d463f199 mv restore into gitgutter#utility#system 2023-08-31 07:50:14 -07:00
Nikita Kouevda
a5e0740801 Restore v:shell_error in autocmd ShellCmdPost
Fixes #869.
2023-08-30 23:43:30 -07:00
Andy Stewart
5f525476f3 Fix <Esc> in nvim floating preview window closes it
Previously the mapping was set in the original window not the floating
window, so <Esc> in the floating window did nothing (when it should have
closed it) while <Esc> in the original window closed the floating window
(when it should have done nothing).

Fixes #868.
2023-08-17 14:14:45 +01:00
Andy Stewart
a7a83c376c Fix closing floating preview window
When a floating window is closed, the cursor automatically goes back to
the original window.  There is no need to try to do this ourselves.

Fixes #866.
2023-08-17 13:45:56 +01:00
Andy Stewart
68f16eb21f Fix handling of file renames
Both `:file` and `:saveas` rename the current file.

`:file` does not write the newly named file to disk, and keeps the same
buffer.  It fires a single `BufFilePre` / `BufFilePost` pair of
autocommands:

    `BufFilePre`     buffer
    `BufFilePost`    buffer

`:saveas` does write the newly named file to disk, in a new buffer.  It
fires two pairs of `BufFilePre` / `BufFilePost` autocommands:

    `BufFilePre`     original buffer
    `BufFilePre`     new buffer
    `BufFilePost`    original buffer
    `BufFilePost`    new buffer

In both cases the cached path needs to be cleared.

See #860, #551.
Fixes #865.
2023-07-31 13:37:11 +01:00
Andy Stewart
458603713d Cast variable getter to match setter 2023-07-31 12:40:24 +01:00
Andy Stewart
8a2f8199b6 Document 'updatetime' and 'signcolumn' more prominently 2023-07-14 14:29:31 +01:00
Andy Stewart
4a7ca061af Add test for dos noeol
See #862.
2023-06-16 09:53:57 +01:00
Andy Stewart
422e4caf79 Ensure inline test functions can be redefined 2023-06-16 09:48:53 +01:00
Andy Stewart
f46652da18 Restore test teardown line
This was accidentally left commented out in the previous commit.
2023-06-16 09:48:53 +01: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
e2056e54c5 Add test for clean/smudge filter
See #796.
2023-06-05 10:52:10 +01:00
Andy Stewart
a202921235 Write buffer before staging whole file
We stage the whole file with `git-add` so we must ensure the file on
disk reflects the buffer's contents.

See #796.
2023-06-05 10:50:17 +01:00
Andy Stewart
278b393e68 Avoid unnecessary concatenation
This is simply to avoid double spaces in the generated commands.  Double
spaces make no practical difference but look slightly inelegant.
2023-06-05 09:52:56 +01:00
Andy Stewart
6ebc0fd233 Extract function to reduce duplication 2023-06-05 09:50:17 +01:00
Andy Stewart
3531f4eddd Remove obsolete link 2023-06-03 15:56:31 +01:00
Andy Stewart
7d425ff4b9 Use filename not path in git add
Since we change directory to the file's directory we can use its name
rather than its path in the repo.
2023-06-03 10:28:47 +01:00
Andy Stewart
f7f1286aac Use filename in clean_smudge_filter_applies() function
And move function to utility.

Since we change directory to the file's directory we can just use its
name rather than it path from the repo root.
2023-06-03 10:26:32 +01:00
Andy Stewart
cefbe30aa9 Make filename() function public 2023-06-03 10:22:20 +01:00
Andy Stewart
a483abb5fc Add timestamp to session log header 2023-06-03 10:09:53 +01:00
Andy Stewart
621b9e77ff Avoid :redir inside execute()
This was happening when starting vim with `let g:gitgutter_log = 1`
and generated E930.
2023-06-03 09:56:17 +01:00
Andy Stewart
538fba90fb Mention clean/smudge filters in readme
See #796.
2023-06-02 16:11:42 +01:00
Andy Stewart
885538efcd Stage entire file if clean/smudge filter applies
If a file is subject to a clean/smudge filter, it is impossible to stage
an individual hunk.  Therefore if the user tries to stage a hunk, ask
whether they want to stage the entire instead.

Determining whether a clean/smudge filter applies is done with:

    git check-attr filter -- path/to/file

– and looking for "unspecified" (not to be) in the output.  The result
is cached so that for a file which is not filtered (the common case),
staging multiple hunks only incurs the cost of the external call once.

See #796.
2023-06-02 16:01:51 +01:00