# Swap file trouble with gvimdiff

4 messages from 2011-02-24 to 2011-02-27. Participants: Marco, Michael J Gruber, Junio C Hamano, David Aguilar.
Thread: https://gitlist.dev/t/26594

## Marco, 2011-02-24 19:34

Subject: Swap file trouble with gvimdiff
Message-ID: <20110224203412.29b732b9@glyph>
URL: https://gitlist.dev/e/20110224203412.29b732b9%40glyph

```
Hi,

I use gvimdiff as difftool. The relevant .gitconfig entries look as follows:

[diff]
	tool = gvimdiff
[difftool]
	prompt = false

But when one diffs a file alredy opened in another window it clashes because
gvimdiff recognises the swap file and throws a message.

It would make sense to pass the option »-n« to gvimdiff to avoid creating a
swap file, since it is not needed here.

I haven't found the place where the command line and arguments for the
supported difftools are placed, so I created a new entry in the .gitconfig

[diff]
	tool = bettergvimdiff
[difftool "bettergvimdiff"]
	cmd = "gvimdiff -f -n \"$LOCAL\" \"$REMOTE\""

I want to know if this is a »correct« solution and — if not — how you solve
the problem.


Marco

```

## Michael J Gruber, 2011-02-25 09:36

Subject: [PATCH] mergetool-lib: call vim in readonly mode for diffs
Message-ID: <227c6e4e11ce964a6e6898afb422d424d46a7b50.1298626494.git.git@drmicha.warpmail.net>
URL: https://gitlist.dev/e/227c6e4e11ce964a6e6898afb422d424d46a7b50.1298626494.git.git%40drmicha.warpmail.net
In-Reply-To: <20110224203412.29b732b9@glyph>

```
When [g]vimdiff is called for files which are opened already, the editor
complains about the existing swap file. But we do not want to write
anything when called from difftool. So, make difftool use "-R" for the
vim family. This

- prevents the use of a swap file and
- marks the buffers readonly.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
Notes:
    It would be nice to mark all buffers but one with -R in mergemode
    but that seems to require some vim-scripting. There are no per-file command
    line options that I know of.

 git-mergetool--lib.sh |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
index 77d4aee..78ce49e 100644
--- a/git-mergetool--lib.sh
+++ b/git-mergetool--lib.sh
@@ -182,7 +182,7 @@ run_merge_tool () {
 			fi
 			check_unchanged
 		else
-			"$merge_tool_path" -f -d -c "wincmd l" \
+			"$merge_tool_path" -R -f -d -c "wincmd l" \
 				"$LOCAL" "$REMOTE"
 		fi
 		;;
@@ -193,7 +193,7 @@ run_merge_tool () {
 				"$LOCAL" "$MERGED" "$REMOTE"
 			check_unchanged
 		else
-			"$merge_tool_path" -f -d -c "wincmd l" \
+			"$merge_tool_path" -R -f -d -c "wincmd l" \
 				"$LOCAL" "$REMOTE"
 		fi
 		;;
-- 
1.7.4.1.224.gefc87

```

## Junio C Hamano, 2011-02-25 20:01

Subject: Re: [PATCH] mergetool-lib: call vim in readonly mode for diffs
Message-ID: <7v62s7anp0.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v62s7anp0.fsf%40alter.siamese.dyndns.org
In-Reply-To: <227c6e4e11ce964a6e6898afb422d424d46a7b50.1298626494.git.git@drmicha.warpmail.net>

```
Michael J Gruber <git@drmicha.warpmail.net> writes:

> When [g]vimdiff is called for files which are opened already, the editor
> complains about the existing swap file. But we do not want to write
> anything when called from difftool. So, make difftool use "-R" for the
> vim family.

Makes sense.  Maint-worthy?

Will queue, thanks.

```

## David Aguilar, 2011-02-27 22:33

Subject: Re: [PATCH] mergetool-lib: call vim in readonly mode for diffs
Message-ID: <20110227223350.GA37866@gmail.com>
URL: https://gitlist.dev/e/20110227223350.GA37866%40gmail.com
In-Reply-To: <7v62s7anp0.fsf@alter.siamese.dyndns.org>

```
On Fri, Feb 25, 2011 at 12:01:15PM -0800, Junio C Hamano wrote:
> Michael J Gruber <git@drmicha.warpmail.net> writes:
> 
> > When [g]vimdiff is called for files which are opened already, the editor
> > complains about the existing swap file. But we do not want to write
> > anything when called from difftool. So, make difftool use "-R" for the
> > vim family.
> 
> Makes sense.  Maint-worthy?

I think this would be good in maint.
thanks,
-- 
		David

```
