使用 gvim for windows 和 msys git 1.7.0.2 使用 fugitive.vim 的 :GDiff 命令时出错

发布于 2024-09-03 05:40:09 字数 343 浏览 5 评论 0原文

当我在 Windows 上时,我一直使用 git 和 fugitive.vim 来管理代码。但是,我遇到了问题。根据 文档, :GDiff 命令应该是一个 diff 窗口并允许我仅暂存文件的一部分。但是,当我在包含更改的文件中发出命令时,我收到以下错误消息: alt text

这是 Windows 的问题吗?维姆?逃亡者? msysgit?文件权限?有人知道吗?

I've been using git along with fugitive.vim to manage code when I'm on windows. However, I've run into a problem. According to the documentation, the :GDiff command should a diff window and allow me to stage only parts of a file. However, when I issue the command in a file with changes, I get the following error message:
alt text

Is this a problem with windows? vim? fugitive? msysgit? file permissions? Anybody know?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

岁月染过的梦 2024-09-10 05:40:09

我遇到了同样的问题 - 这是我解决它的方法。

默认情况下,Vim 会尝试将交换文件存储在原始文件旁边。 Fugitive 创建一个不对应于任何真实文件路径的缓冲区,因此 Vim 在尝试创建交换文件时会失败。解决方案是确保 Vim 有一个可以写入的路径。

我是这样解决这个问题的:

if has("win32") || has("win64")
   set directory=$TMP
else
   set directory=~/tmp
end

这是 GitHub 上的原始问题:
https://github.com/tpope/vim-fugitive/issues/9

编辑:

正如下面fow指出的那样,最好使用如下所示的内容:

set directory+=,~/tmp,$TMP

Vim 应该使用它可以使用的第一个路径。

I had the same problem - here's how I fixed it.

By default, Vim will try to store swap files beside the original. Fugitive creates a buffer that does not correspond to any real file path, so Vim barfs when it tries to create the swap file. The solution is to make sure that Vim has a path it can write to.

Here's how I fixed this:

if has("win32") || has("win64")
   set directory=$TMP
else
   set directory=~/tmp
end

Here's the original issue on GitHub:
https://github.com/tpope/vim-fugitive/issues/9

EDIT:

As fow points out below, it's probably better to use something like the following:

set directory+=,~/tmp,$TMP

Vim should use the first path it can.

玉环 2024-09-10 05:40:09

我没有 Windows 计算机,但我能够在 Mac OS X 10.6 系统上重现并隔离此问题。

创建 C:\TMPC:\TEMP (:help 'directory' 表示两者都在 Windows 版本的 Vim 上的 directory 选项的默认值中),或者将现有目录添加到directory选项的值中。

我在我的主目录下使用 Vim 特定的临时目录(同样,这里没有 Windows)并添加两个尾部斜杠 (~/tmp/.vim-swaps//)。这种设置集中交换文件,但根据正在编辑的文件的目录为它们提供唯一的名称。请参阅 :help :swapname 以及
:help 中的“如果目录以两个路径分隔符结尾”位“目录”

使用 ^= 前置 1 您的目录(以便始终使用它(如果存在):

set directory^=C:\\some\\existing\\directory//

或者,使用 += 附加您的目录目录(以便仅在存在且不存在其他适用的 directory 条目时使用它):

set directory+=C:\\some\\existing\\directory//

Charles 的回答表明 $TMP (参考环境变量)对于 Windows 可能是一个不错的值:

set directory+=$TMP//

根本原因与 directory 选项的默认值与 :Gdiff 索引的路径名相结合“伪”文件。

:Gdiff 视图索引端的缓冲区使用特殊的路径名,如下所示 fugitive:///path/to/repository/.git//0/path/to/file /under/repository (逃逸捕获对所谓缓冲区的读取和写入,并通过调用 Git“管道”命令将它们重定向到索引)。

目录中的第一个条目通常是.。这意味着 Vim 将尝试将交换文件放在与编辑的文件相同的目录中(即 foo/bar.txt 将尝试使用 foo/.bar.swp) 。如果无法创建此首选交换文件,则将尝试 directory 中的后续条目。

. 作为第一个 目录,为 fugitive:///path/to/repository/.git//0/path/to/file 的首选交换文件/under/repository 将是 fugitive:///path/to/repository/.git//0/path/to/file/under/.repository.swp。该路径名的前导部分(fugitive:pathto 等)可能不存在,因此 Vim 将继续执行目录中的下一个条目。如果没有其他目录条目可用于创建交换文件(例如它们不存在),那么您会收到错误E302。

我能够使用 set directory=.,~/no-such-dir,/var/no-such-dir,/no-such-dir 在 Unix-y 系统上重现您的问题(即采用默认的 Unix 值并将出现的 tmp 更改为 no-such-dir)。实际上,“no-such-dir”目录都不存在。当我使用 :Gdiff 时,我遇到了同样的错误。

1
:help :set^= 只表示“add”,但代码显示 set listopt^=... 的前置方式类似于 set listopt+=... 的附加方式(正如后者记录的那样) 。两者都应该根据需要自动插入逗号(尽管这方面可能存在错误)。

I do not have a Windows machine, but I was able to reproduce and isolate this problem on a Mac OS X 10.6 system.

Either create C:\TMP or C:\TEMP (:help 'directory' says both are in the default value of the directory option on Windows builds of Vim), or add an existing directory to the value of the directory option.

I use a Vim-specific temporary directory under my home directory (again, no Windows here) and add two trailing slashes (~/tmp/.vim-swaps//). This kind of setting centralizes the swap files but gives them unique names based on the directories of the files being edited. See “Advantages” and “Disadvantages” in :help :swapname as well as the
“if a directory ends in two path separators” bit in :help 'directory'.

Use ^= to prepend1 your directory (so that it is always used, if it exists):

set directory^=C:\\some\\existing\\directory//

Or, use += to append your directory (so that it is only used if it exists and no other applicable directory entries exist):

set directory+=C:\\some\\existing\\directory//

Charles’ answer suggests that $TMP (a reference to an environment variable) might be a good value for Windows:

set directory+=$TMP//

The root cause is related to the default value of the directory option combined with the pathname of :Gdiff’s index “pseudo” file.

The buffer for the index side of a :Gdiff view uses a special pathname that looks like fugitive:///path/to/repository/.git//0/path/to/file/under/repository (fugitive captures reads and writes to so named buffers and redirects them to the index by invoking Git “plumbing” commands).

The first entry in directory is usually .. This means that Vim will try to put the swapfile in the same directory as the edited file (i.e. foo/bar.txt will try to use foo/.bar.swp). If this preferred swapfile can not be created, then subsequent entries from directory will be tried.

With . as the first directory, the preferred swapfile for fugitive:///path/to/repository/.git//0/path/to/file/under/repository will be fugitive:///path/to/repository/.git//0/path/to/file/under/.repository.swp. The leading components of this pathname (fugitive:, path, to, etc.) probably do not exist, so Vim will go on to the next entry from directory. If none of the other directory entries are usable for creating swap files (e.g. they do not exist), then you get error E302.

I was able to reproduce your problem on a Unix-y system by using set directory=.,~/no-such-dir,/var/no-such-dir,/no-such-dir (i.e. taking the default Unix value and changing occurrences of tmp to no-such-dir). None of the “no-such-dir” directories actually existed. I got the same error when I use :Gdiff.

1
:help :set^= only says “add”, but the code shows that set listopt^=… prepends similar to how set listopt+=… appends (as the latter is documented to do). Both should automatically insert commas as needed (though there may have been bugs in this area).

那支青花 2024-09-10 05:40:09

这可能与 msysgit 的 问题 428 有关在我的回答中提到

尝试按照我之前的回答中所述修补 cmd/git.cmd ,看看是否有帮助。

除此之外,还有两个选择:

  • 要么是锁定问题(文件被进程锁定):像 进程监视器进程浏览器 可能有助于查看是否是这种情况(以及该交换文件上到底有什么句柄)
  • 或 Git 问题。一个好技巧是安装 msysgit 的网络安装程序,它将在您的 Windows 上构建最新版本的 Git。然后,您可以尝试查看该更新版本是否仍然存在问题。
    注意:第三个选项,尝试降级 Git,再次排除与该工具的任何链接。

That may be related to the issue 428 of msysgit mentioned in my SO answer.

Try patching the cmd/git.cmd as I describe in my previous answer and see if this help.

Baring that, 2 options remains:

  • either a locking problem (the file is locked by a process): an utility like process monitor or process explorer might help to see if it is the case (and what handle exactly there is on that swap file)
  • or a Git issue. One good trick is then to install the net-installer of msysgit, which will build the latest version of Git on your Windows. You can then try and see if the problem persists with that updated version.
    Note: third option, trying to downgrade Git, again to rule out any link with that tool.
欲拥i 2024-09-10 05:40:09

顺便说一句,当我尝试 :gdiff 未保存的文件时,我遇到了同样的错误 - 当我保存它时 (:w) 它有效!

BTW same error I got, when I tried to :gdiff unsaved file - when i saved it (:w) it works!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文