Include regex.[ch] in compat/
[git/mingw/4msysgit/wingit-dll.git] / git-merge-stupid.sh
blob4faecb933df33fd4b72e0968d7ee04e1ccc49aec
1 #!/bin/sh
3 # Copyright (c) 2005 Linus Torvalds
5 # Resolve two trees, 'stupid merge'.
7 # The first parameters up to -- are merge bases; the rest are heads.
8 bases= head= remotes= sep_seen=
9 for arg
11 case ",$sep_seen,$head,$arg," in
12 *,--,)
13 sep_seen=yes
15 ,yes,,*)
16 head=$arg
18 ,yes,*)
19 remotes="$remotes$arg "
22 bases="$bases$arg "
24 esac
25 done
27 # Give up if we are given more than two remotes -- not handling octopus.
28 case "$remotes" in
29 ?*' '?*)
30 exit 2 ;;
31 esac
33 # Find an optimum merge base if there are more than one candidates.
34 case "$bases" in
35 ?*' '?*)
36 echo "Trying to find the optimum merge base."
37 G=.tmp-index$$
38 best=
39 best_cnt=-1
40 for c in $bases
42 rm -f $G
43 GIT_INDEX_FILE=$G git-read-tree -m $c $head $remotes \
44 2>/dev/null || continue
45 # Count the paths that are unmerged.
46 cnt=`GIT_INDEX_FILE=$G git-ls-files --unmerged | wc -l`
47 if test $best_cnt -le 0 -o $cnt -le $best_cnt
48 then
49 best=$c
50 best_cnt=$cnt
51 if test "$best_cnt" -eq 0
52 then
53 # Cannot do any better than all trivial merge.
54 break
57 done
58 rm -f $G
59 common="$best"
62 common="$bases"
64 esac
66 git-update-index --refresh 2>/dev/null
67 git-read-tree -u -m $common $head $remotes || exit 2
68 echo "Trying simple merge."
69 if result_tree=$(git-write-tree 2>/dev/null)
70 then
71 exit 0
72 else
73 echo "Simple merge failed, trying Automatic merge."
74 if git-merge-index -o git-merge-one-file -a
75 then
76 exit 0
77 else
78 exit 1