我在我的Subversion配置文件中指定了merge-tool-cmd = meld
。当我使用提供的冲突解决选项之一(如选项l)来解决合并冲突时,我收到以下消息:
meld: error: too many arguments (wanted 0-4, got 5)
The external merge tool exited with exit code 2
有人能够诊断问题/提供解决方案吗?谢谢。
首先警告一下!如果操作不当很容易丢失本地编辑的内容!测试测试测试!
很遗憾,pmod链接中的脚本不适用于svn 1.6(Ubuntu 11.04中的当前版本)。结合pmod链接和这里的代码以及此处的建议,我制作了这个脚本,看起来工作正常:
#!/usr/bin/env python
# svn merge-tool python wrapper for meld
import sys
import subprocess
try:
# path to meld
meld = "/usr/bin/meld"
# file paths
base = sys.argv[1]
theirs = sys.argv[2]
mine = sys.argv[3]
merged = sys.argv[4]
# the call to meld
# For older meld versions:
# cmd = [meld, mine, base, theirs, merged]
# New meld versions: >= 1.8.4
cmd = [meld, mine, base, theirs, '-o', merged]
# Call meld, making sure it exits correctly
subprocess.check_call(cmd)
except:
print "Oh noes, an error!"
sys.exit(-1)
将此文件保存到合适的位置(例如/usr/local/bin/svn-merge-meld.py
),并使其可执行:
sudo chmod +x /usr/local/bin/svn-merge-meld.py
然后编辑~/.subversion/config
文件,取消注释merge-tool-cmd =
这一行,并将路径设置为您的命令。
注意,当发生冲突时,会提示您如何处理。您需要输入一个单独的l
,让svn运行此脚本。完成合并后,您需要输入r
来解决冲突并将合并版本复制到工作副本中。
drevicko的回答是正确的,但需要使用Python。这个回答提供了一个bash脚本的替代方案:
#!/bin/bash
base=${1?1st arg is the 'base' file}
theirs=${2?2nd arg is 'theirs' file}
mine=${3?3rd arg is 'mine' file}
merged=${4?4th arg is the 'merged' file}
cat "$mine" > "$merged"
meld -L "Base=${base##*/}" "$base" \
-L "Mine->Merged=${merged##*/}" "$merged" \
-L "Theirs=${theirs##*/}" "$theirs" \
-o "$merged"
将上述脚本复制到文件svn-merge-meld.sh
中,并使用以下命令添加执行权限:
chmod +x svn-merge-meld.sh
最后编辑您的svn配置:
vi ~/.subversion/config
并启用 merge-tool-cmd
:
[helpers]
merge-tool-cmd = /path/to/svn-merge-meld.sh
#!/usr/local/bin/python3
# svn merge-tool python wrapper for meld
import sys
import subprocess
try:
# path to meld
meld = "/usr/bin/meld"
# file paths
base = sys.argv[1]
theirs = sys.argv[2]
mine = sys.argv[3]
merged1 = sys.argv[4]
merged2 = sys.argv[5]
print(14*"*" + " MELD was called with " + 14*"*")
print(f"base = {base}")
print(f"theirs = {theirs}")
print(f"mine = {mine}")
print(f"merged1 = {merged1}")
print(f"merged2 = {merged2}")
# the call to meld
cmd = [meld, mine, base, theirs, '-o', merged1, '--auto-merge', '-L', 'mine -> base(merged) <-theirs']
# Call meld, making sure it exits correctly
subprocess.check_call(cmd)
except Exception:
print("There was an error calling meld!")
sys.exit(-1)
print(50*"*")
cmd = [meld, mine, base, theirs, '-o', merged]
(meld 1.8.4)。 - Ayrat