2011-01-26 2 views
25

SVN에서 충돌을 알릴 때 kdiff3을 사용하여 충돌을 해결하고 싶습니다. 어떻게 이것을 기본 도구로 설정할 수 있습니까?SVN 병합 도구로 kdiff3을 설정하는 방법

### Set merge-tool-cmd to the command used to invoke your external 
### merging tool of choice. Subversion will pass 4 arguments to 
### the specified command: base theirs mine merged 
# merge-tool-cmd = merge_command 

네 일반 인수를 지원하지 않는 kdiff3에 문제가 있지만 (SVN 네를 전달합니다

답변

28

서브 버전 구성 파일 (/etc/subversion/config 또는 ~/.subversion/config)로 이동하고, 좋아하는 도구로 merge-tool-cmd 변수를 설정 일반 인수 kdiff3, 그리고 작동하지 않습니다), 그래서 일반적으로 예를 들면, "kdiff3caller"인수를 변환하는 간단한 스크립트로 호출됩니다

#!/bin/sh 
kdiff3 "$1" "$2" "$3" -o "$4" 

이 kdiff3 문제 및 졸 is 설명은 here입니다.

+0

나는 그것을 시험해보고 어떻게 작동하는지 보겠습니다. – gruszczy

+1

공백이 포함 된 파일 이름에 대해서도 작업하려면'kdiff3 "$ 1" "$ 2" ""$ 3 "-o"$ 4 "'를 사용하십시오. – hlovdal

+2

나를 위해 kdiff3 ok를 시작하지만 작동하지 않는 것 같습니다. 나는 svn merge를한다. 갈등이있을 때 나는 "launch (l)"을하고 kdiff3를 연다. 그러나 merge가 작동하지 않는 것처럼 보인다. 그것은 .svn/tmp로 저장하지만 svn merge 명령은 반복적으로 스스로 무엇을해야 하는지를 묻습니다. 편집 : 확인, 내 잘못입니다. 나는 일을하지만 먼저 발사를하고 병합을 한 다음 (r) 해결을 선택해야합니다. – PapaFreud

3

이 스크립트는 어딘지 기억이 나지 않습니다. 그러나 저자는 Michael Bradley입니다.

내 답변은 Jon Ander Ortiz Durántez의 답변과 유사합니다. 그래서 그의 대답이 효과가 없다면, 당신은 백업을 가지고 있습니다. 한번은 그가 제안한 것과 같은 것을 시도했지만, 모든 것을 해결 한이 스크립트를 찾을 때까지 항상 매개 변수로 약간의 오류를 출력했습니다.

스크립트 파일을 만들고 yvoyer의 대답에서 ~/.subversion/config

 
#!/bin/bash 

# Return an errorcode of 0 on successful merge, 1 if unresolved conflicts 
# remain in the result. Any other errorcode will be treated as fatal. 
# Author: Michael Bradley 

#NOTE: all output must be redirected to stderr with "1>&2" as all stdout output is written to the output file 

# Must be called by subversion in "~/.subversion/config" file 
# Add config : "diff-cmd = /path/to/script/myKdiff3.sh" 

VDIFF3="kdiff3" 
DIFF3="diff3" 
DIFF="kdiff3" 

promptUser() 
{ 
    read answer 
    case "${answer}" in 

     "M"  ) 
     echo "" 1>&2 
     echo "Attempting to merge ${baseFileName} with ${DIFF}" 1>&2 
     $VDIFF3 $older $mine $theirs --L1 $labelOlder --L2 $labelMine --L3 $labelTheirs -o $output 1>&2 
     bLoop=1 
     if [ -f $output ]; then 
      if [ -s $output ]; then 
       #output succesfully written 
       bLoop=0 
      fi 
     fi 
     if [ $bLoop = 0 ]; then 
      cat $output 
      rm -f $output 
      exit 0 
     else 
      echo "Merge failed, try again" 1>&2 
     fi 

     ;; 

     "m"  ) 
     echo "" 1>&2 
     echo "Attempting to auto-merge ${baseFileName}" 1>&2 
     diff3 -L $labelMine -L $labelOlder -L $labelTheirs -Em $mine $older $theirs > $output 
     if [ $? = 1 ]; then 
      #Can't auto merge 
      rm -f $output 
      $VDIFF3 $older $mine $theirs --L1 $labelOlder --L2 $labelMine --L3 $labelTheirs -o $output --auto 1>&2 
      bLoop=1 
      if [ -f $output ]; then 
       if [ -s $output ]; then 
        #output succesfully written 
        bLoop=0 
       fi 
      fi 
      if [ $bLoop = 0 ]; then 
       cat $output 
       rm -f $output 
       exit 0 
      else 
       echo "Merge failed, try again" 1>&2 
      fi 
     else 
      #We can automerge, and we already did it 
      cat $output 
      rm -f $output 
      exit 0 
     fi 
     ;; 

     "diff3" | "Diff3" | "DIFF3" ) 
     echo "" 1>&2 
     echo "Diffing..." 1>&2 
     $VDIFF3 $older $mine $theirs --L1 $labelOlder --L2 $labelMine --L3 $labelTheirs 1>&2 
     ;; 

     "diff" | "Diff" | "DIFF" ) 
     echo "" 1>&2 
     echo "Diffing..." 1>&2 
     $DIFF $mine $theirs -L $labelMine -L $labelTheirs 1>&2 
     ;; 

     "A" | "a" ) 
     echo "" 1>&2 
     echo "Accepting remote version of file..." 1>&2 
     cat ${theirs} 
     exit 0 
     ;; 

     "I" | "i" ) 
     echo "" 1>&2 
     echo "Keeping local modifications..." 1>&2 
     cat ${mine} 
     exit 0 
     ;; 

     "R" | "r" ) 
     echo "" 1>&2 
     echo "Reverting to base..." 1>&2 
     cat ${older} 
     exit 0 
     ;; 

     "D" | "d" ) 
     echo "" 1>&2 
     echo "Runnig diff3..." 1>&2 
     diff3 -L $labelMine -L $labelOlder -L $labelTheirs -Em $mine $older $theirs 
     #Exit with return vaule of the diff3 (to write out files if necessary) 
     exit $? 
     ;; 

     "S" | "s" ) 
     echo "" 1>&2 
     echo "Saving for later..." 1>&2 
     cat ${mine} 
     #Exit with return vaule of 1 to force writting of files 
     exit 1 
     ;; 

     "Fail" | "fail" | "FAIL" ) 
     echo "" 1>&2 
     echo "Failing..." 1>&2 
     exit 2 
     ;; 

     "H" | "h" ) 
     echo "" 1>&2 
     echo "USAGE OPTIONS:" 1>&2 
     echo " [A]ccept Accept $labelTheirs and throw out local modifications" 1>&2 
     echo " [D]efault Use diff3 to merge files (same behavior as vanilla SVN)" 1>&2 
     echo " [Fail]  Kills the command (not suggested)" 1>&2 
     echo " [H]elp  Print this message" 1>&2 
     echo " [I]gnore Keep your locally modified version as is" 1>&2 
     echo " [M]erge  Manually merge using ${VDIFF3}" 1>&2 
     echo " [m]erge  Same as "M" but attempts to automerge if possible" 1>&2 
     echo " [R]evert Revert to base version (${labelOlder})" 1>&2 
     echo " [S]ave  Same as 'I' but writes out rold, rnew, and rmine files to deal with later" 1>&2 
     echo " [diff]  Type 'diff' to diff versions $labelMine and $labelTheirsthe before making a descision" 1>&2 
     echo " [diff3]  Type 'diff3' to diff all three versions before making a descision" 1>&2 
     echo "" 1>&2 
     ;; 

     * ) 
     echo "'${answer}' is not an option, try again." 1>&2 
     ;; 
    esac 
} 

if [ -z $2 ] 
then 
    echo ERROR: This script expects to be called by subversion 
    exit 1 
fi 

if [ $2 = "-m" ] 
then 
    #Setup vars 
    labelMine=${4} 
    labelOlder=${6} 
    labelTheirs=${8} 
    mine=${9} 
    older=${10} 
    theirs=${11} 
    output=${9}.svnDiff3TempOutput 
    baseFileName=`echo $mine | sed -e "s/.tmp$//"` 

    #Prompt user for direction 
    while [ 1 ] 
    do 
     echo "" 1>&2 
     echo "${baseFileName} requires merging." 1>&2 
     echo "" 1>&2 
     echo "What would you like to do?" 1>&2 
     echo "[M]erge [A]ccept [I]gnore [R]evert [D]efault [H]elp" 1>&2 
     promptUser 
    done 
else 
    L="-L"   #Argument option for left label 
    R="-L"   #Argument option for right label 
    label1=$3  #Left label 
    label2=$5  #Right label 
    file1=$6  #Left file 
    file2=$7  #Right file 

    $DIFF $file1 $file2 $L "$label1" $L "$label2" & 
    #$DIFF $file1 $file2 & 
    #wait for the command to finish 
    wait 
fi 
exit 0 
+0

이 스크립트는 공백이있는 파일 이름을 따옴표로 수정하지 않고서는 처리 할 수 ​​없습니다.'$ older'에 대한 참조를' "$ older"등. –

+1

어쩌면 당신은 [여기] (https://negativesum.net/tech/log/using-kdiff3-with-svn/)을 발견 했습니까? –

+0

@AdamSpiers, 출처에 감사드립니다. – yvoyer

3

스크립트에 diff-cmd = /path/to/script.sh을 설정 나를 위해 잘 작동, 나는 SVN 1.4 사용하고 있습니다. Jon Ander Ortiz Durntez의 이전 답변은 SVN 1.5 이상에서 작동하며이 스크립트는 SVN 1.5 이전 버전에서 작동합니다. 버전 1.5의 경우 --diff-cmd & --diff3-cmd가 변경된 것으로 보입니다. 약간의 차이를 보려면 다음 2 개 SVN의 문서에 스크립트를 비교 :

내가 svn update 동안 충돌을 얻는 경우에 지금은 모든 너무 어렵다은 ">>>>>>>>"충돌 마커를 사용하여 파일을 통해 토하고 대신 kdiff3로 개막 이후 마이클 브래들리의 스크립트 정말 유용 복잡한 고발이있을 경우 해결할 수 있습니다. diff3-cmd는 병합 및 업데이트에 모두 사용할 수 있습니다.

나는 diff3-cmd = /usr/local/bin/svndiff3~/.subversion/config에 추가 (또는있는 CmdLine에 --diff3-cmd 사용) 내가 아니면 sdiff에 svn diff을 보내 내 자신의 스크립트를 작성하고 --diff-cmd에 의해 지정되어 있기 때문이다.

이 스크립트는 yolinux에 게시되며 약간 수정 된 버전 (자동 병합 기능)은 여기 Jawspeak에 게시됩니다.

4

짧고 (SVN 1.7.7에서 테스트) SVN의 이후 버전에서 작동하는 솔루션 :

~/SVN 병합 - kdiff

#!/bin/bash 

# Useful when something fails 
LOG=~/svn-merge-kdiff-last-run.log 
echo "arguments passed to $0: [email protected]" > $LOG 

# Now, don't think you will get the $1, $2, etc... by referencing. 
# At first, you have to copy it to an array 
for i in [email protected]; do 
    args=(${args[@]} $i) 
done 

echo "parsed args" >> $LOG 
for i in ${args[@]}; do 
    echo $i >> $LOG 
done 

# I keep it in case something changes 
if [ "${args[1]}" == "-m" ] && [ "${args[2]}" == "-L" ] && [ "${args[3]}" == ".mine" ];then 
    command="kdiff3 --L1 ${args[5]} --base ${args[9]} --L2 ${args[7]} ${args[10]} --L3 ${args[3]} ${args[8]} -o merged" 
    $command 
    if [[ $? -ne 0 ]]; then 
     echo "$command failed" >> $LOG 
     exit 1 
    fi 

    # You have to do this, otherwise after the merge you will see... empty file(?) 
    cat merged 

    rm merged 
    exit 0 
fi 

exit -1 

그것을 바인딩하는 스크립트를 작성 svn에서 ~ /.subversion/config

diff3-cmd = ~/svn-merge-kdiff 
+0

불행히도 SVN 1.7.18에서 작동하지 않습니다. – villapx