]>
Commit | Line | Data |
---|---|---|
839a7a06 LT |
1 | #!/bin/sh |
2 | # | |
3 | # This is the git merge script, called with | |
4 | # | |
e3b4be7f LT |
5 | # $1 - original file SHA1 (or empty) |
6 | # $2 - file in branch1 SHA1 (or empty) | |
7 | # $3 - file in branch2 SHA1 (or empty) | |
839a7a06 LT |
8 | # $4 - pathname in repository |
9 | # | |
10 | # | |
e3b4be7f LT |
11 | # Handle some trivial cases.. The _really_ trivial cases have |
12 | # been handled already by read-tree, but that one doesn't | |
13 | # do any merges that migth change the tree layout | |
839a7a06 | 14 | # |
e3b4be7f | 15 | |
0a9ea850 JB |
16 | # if the directory is newly added in a branch, it might not exist |
17 | # in the current tree | |
18 | dir=$(dirname "$4") | |
19 | mkdir -p "$dir" | |
20 | ||
e3b4be7f | 21 | case "${1:-.}${2:-.}${3:-.}" in |
839a7a06 | 22 | # |
e2b6a9d0 JB |
23 | # deleted in both |
24 | # | |
25 | "$1..") | |
26 | echo "ERROR: $4 is removed in both branches" | |
27 | echo "ERROR: This is a potential rename conflict" | |
28 | exit 1;; | |
29 | # | |
30 | # deleted in one and unchanged in the other | |
839a7a06 | 31 | # |
e3b4be7f LT |
32 | "$1.." | "$1.$1" | "$1$1.") |
33 | rm -f -- "$4" | |
e2b6a9d0 | 34 | echo "Removing $4" |
e3b4be7f | 35 | update-cache --remove -- "$4" |
839a7a06 | 36 | exit 0 |
e3b4be7f LT |
37 | ;; |
38 | ||
839a7a06 | 39 | # |
e2b6a9d0 | 40 | # added in one |
839a7a06 | 41 | # |
e2b6a9d0 JB |
42 | ".$2." | "..$3" ) |
43 | echo "Adding $4 with perm $6$7" | |
44 | mv $(unpack-file "$2$3") $4 | |
45 | chmod "$6$7" $4 | |
e3b4be7f LT |
46 | update-cache --add -- $4 |
47 | exit 0 | |
48 | ;; | |
e2b6a9d0 JB |
49 | # |
50 | # Added in both (check for same permissions) | |
51 | # | |
52 | ".$2$2") | |
53 | if [ "$6" != "$7" ]; then | |
54 | echo "ERROR: File $4 added in both branches, permissions conflict $6->$7" | |
55 | exit 1 | |
56 | fi | |
57 | echo "Adding $4 with perm $6" | |
58 | mv $(unpack-file "$2") $4 | |
59 | chmod "$6" $4 | |
60 | update-cache --add -- $4 | |
61 | exit 0;; | |
e3b4be7f LT |
62 | # |
63 | # Modified in both, but differently ;( | |
64 | # | |
65 | "$1$2$3") | |
66 | echo "Auto-merging $4" | |
67 | orig=$(unpack-file $1) | |
68 | src1=$(unpack-file $2) | |
69 | src2=$(unpack-file $3) | |
0a9ea850 | 70 | merge "$src2" "$orig" "$src1" |
e2b6a9d0 JB |
71 | ret=$? |
72 | if [ "$6" != "$7" ]; then | |
73 | echo "ERROR: Permissions $5->$6->$7 don't match merging $src2" | |
74 | if [ $ret -ne 0 ]; then | |
75 | echo "ERROR: Leaving conflict merge in $src2" | |
76 | fi | |
77 | exit 1 | |
78 | fi | |
79 | chmod -- "$6" "$src2" | |
80 | if [ $ret -ne 0 ]; then | |
81 | echo "ERROR: Leaving conflict merge in $src2" | |
0a9ea850 JB |
82 | exit 1 |
83 | fi | |
e2b6a9d0 | 84 | cp -- "$src2" "$4" && chmod -- "$6" "$4" && update-cache --add -- "$4" && exit 0 |
e3b4be7f LT |
85 | ;; |
86 | ||
87 | *) | |
88 | echo "Not handling case $1 -> $2 -> $3" | |
89 | ;; | |
90 | esac | |
91 | exit 1 |