Follow-up to r29036: Now that the "mergeinfo" transaction file is no
[svn.git] / contrib / client-side / svn-resolve
blob3dbdb3a9086b5d19b38243256743e5ceaab384ae
1 #!/bin/sh
2 # -*- coding:utf-8;mode:shell-script;mode:font-lock -*-
4 ##
5 # Resolve Subversion conflicts using FileMerge.
7 # (FileMerge is a graphical diff tool in the Mac OS X Developer
8 # Tools.)
10 # In your working copy, do (for example):
12 # svn-resolve .
14 # FileMerge will open a window for each file that is in a conflict
15 # state, showing you diffs with the left/right arrows pointing to the
16 # side of each change that is selected. Diffs with gray outlines are
17 # automatically resolved. Diffs with red outlines are the conflicts.
18 # Find those and select which side you want, or pull up the split view
19 # at he bottom and edit the text to what it should be.
21 # Copyright (c) 2002 Wilfredo Sanchez Vega <wsanchez@wsanchez.net>.
22 # All rights reserved.
24 # Permission to use, copy, modify, and distribute this software for
25 # any purpose with or without fee is hereby granted, provided that the
26 # above copyright notice, this permission, and the following
27 # disclaimer notice appear in all copies.
29 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL
30 # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
31 # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
32 # AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
33 # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
34 # OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
35 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
36 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
39 set -e
40 set -u
43 # Handle command line
46 usage ()
48 program=$(basename "$0");
50 if [ $# != 0 ]; then echo "$@"; echo ""; fi;
52 echo "${program}: usage:";
53 echo " ${program} file1 [file2 ...]";
56 # Process arguments
57 while [ $# != 0 ]; do
58 case "$1" in
59 --help)
60 usage;
61 exit 0;
63 --|*) break; ;;
64 esac;
65 done;
68 # Do The Right Thing
72 # If opendiff isn't installed, you can't launch FileMerge.
73 # If we're not in the OS X Terminal, we probably can't run FileMerge
75 if ! type opendiff >& /dev/null || [ "${TERM_PROGRAM:=}" != "Apple_Terminal" ]; then
76 diff "$@";
77 exit $?;
78 fi;
80 find_ancestor ()
82 local conflict="$1";
83 local which="$2";
85 n=$(ls -1 "${conflict}.merge-${which}.r"* 2>/dev/null | wc -l);
87 if [ "${n}" -eq 0 ]; then
88 echo "ERROR: No ${which} ancenstor found."
89 return 1;
90 fi;
92 if [ "${n}" -gt 1 ]; then
93 echo "ERROR: Multible ${which} ancenstors found:"
94 ls -1 "${conflict}.merge-left.r"*
95 return 1;
96 fi;
98 ls "${conflict}.merge-${which}.r"*
101 resolve ()
103 local conflict="$1";
105 local revision="$(svn info "${conflict}" | grep '^Revision: ' | sed 's|^Revision: ||')";
107 local left="${conflict}.working";
108 local right="$(find_ancestor "${conflict}" right)";
109 local ancestor="$(find_ancestor "${conflict}" left )";
111 for file in "${left}" "${right}" "${ancestor}"; do
112 if [ ! -f "${file}" ]; then
113 echo "ERROR: Missing file: ${file}";
114 return 1;
116 done;
118 opendiff "${left}" "${right}" -ancestor "${ancestor}" -merge "${conflict}";
121 for file in "$@"; do
122 for conflict in $(svn status . | grep '^C' | sed 's|^C......||'); do
123 resolve "${conflict}";
124 done;
125 done;