]>
Commit | Line | Data |
---|---|---|
839a7a06 LT |
1 | #!/bin/sh |
2 | # | |
ec73962d PB |
3 | # Copyright (c) Linus Torvalds, 2005 |
4 | # | |
5 | # This is the git per-file merge script, called with | |
839a7a06 | 6 | # |
e3b4be7f LT |
7 | # $1 - original file SHA1 (or empty) |
8 | # $2 - file in branch1 SHA1 (or empty) | |
9 | # $3 - file in branch2 SHA1 (or empty) | |
839a7a06 | 10 | # $4 - pathname in repository |
ee28152d JH |
11 | # $5 - orignal file mode (or empty) |
12 | # $6 - file in branch1 mode (or empty) | |
13 | # $7 - file in branch2 mode (or empty) | |
839a7a06 | 14 | # |
e3b4be7f | 15 | # Handle some trivial cases.. The _really_ trivial cases have |
0fc65a45 | 16 | # been handled already by git-read-tree, but that one doesn't |
ec73962d | 17 | # do any merges that might change the tree layout. |
0a9ea850 | 18 | |
e0226add LT |
19 | verify_path() { |
20 | file="$1" | |
21 | dir=`dirname "$file"` && | |
22 | mkdir -p "$dir" && | |
23 | rm -f -- "$file" && | |
24 | : >"$file" | |
25 | } | |
26 | ||
e3b4be7f | 27 | case "${1:-.}${2:-.}${3:-.}" in |
839a7a06 | 28 | # |
ee28152d | 29 | # Deleted in both. |
e2b6a9d0 JB |
30 | # |
31 | "$1..") | |
2a68a865 LT |
32 | echo "WARNING: $4 is removed in both branches." |
33 | echo "WARNING: This is a potential rename conflict." | |
566487c8 LT |
34 | rm -f -- "$4" && |
35 | exec git-update-cache --remove -- "$4" | |
ec73962d PB |
36 | ;; |
37 | ||
e2b6a9d0 | 38 | # |
ee28152d | 39 | # Deleted in one and unchanged in the other. |
839a7a06 | 40 | # |
ec73962d | 41 | "$1.$1" | "$1$1.") |
e2b6a9d0 | 42 | echo "Removing $4" |
e0226add LT |
43 | rm -f -- "$4" && |
44 | exec git-update-cache --remove -- "$4" | |
ec73962d PB |
45 | ;; |
46 | ||
839a7a06 | 47 | # |
ee28152d | 48 | # Added in one. |
839a7a06 | 49 | # |
e2b6a9d0 | 50 | ".$2." | "..$3" ) |
21a08dcb | 51 | case "$6$7" in *7??) mode=+x;; *) mode=-x;; esac |
ee28152d | 52 | echo "Adding $4 with perm $mode." |
e0226add LT |
53 | verify_path "$4" && |
54 | git-cat-file blob "$2$3" >"$4" && | |
ec73962d | 55 | chmod $mode -- "$4" && |
e0226add | 56 | exec git-update-cache --add -- "$4" |
ec73962d PB |
57 | ;; |
58 | ||
e2b6a9d0 | 59 | # |
ee28152d | 60 | # Added in both (check for same permissions). |
e2b6a9d0 | 61 | # |
ee28152d | 62 | ".$3$2") |
e2b6a9d0 | 63 | if [ "$6" != "$7" ]; then |
ee28152d JH |
64 | echo "ERROR: File $4 added identically in both branches," |
65 | echo "ERROR: but permissions conflict $6->$7." | |
e2b6a9d0 JB |
66 | exit 1 |
67 | fi | |
21a08dcb JH |
68 | case "$6" in *7??) mode=+x;; *) mode=-x;; esac |
69 | echo "Adding $4 with perm $mode" | |
e0226add LT |
70 | verify_path "$4" && |
71 | git-cat-file blob "$2" >"$4" && | |
ec73962d | 72 | chmod $mode -- "$4" && |
e0226add | 73 | exec git-update-cache --add -- "$4" |
ec73962d PB |
74 | ;; |
75 | ||
e3b4be7f | 76 | # |
ee28152d | 77 | # Modified in both, but differently. |
e3b4be7f LT |
78 | # |
79 | "$1$2$3") | |
ee28152d | 80 | echo "Auto-merging $4." |
c7d1d4e1 JH |
81 | orig=`git-unpack-file $1` |
82 | src1=`git-unpack-file $2` | |
83 | src2=`git-unpack-file $3` | |
ec73962d | 84 | |
e0226add LT |
85 | verify_path "$4" && |
86 | merge -p "$src1" "$orig" "$src2" > "$4" | |
e2b6a9d0 | 87 | ret=$? |
2a68a865 | 88 | rm -f -- "$orig" "$src1" "$src2" |
8544a6f1 | 89 | |
e2b6a9d0 | 90 | if [ "$6" != "$7" ]; then |
ec73962d | 91 | echo "ERROR: Permissions conflict: $5->$6,$7." |
2a68a865 | 92 | ret=1 |
e2b6a9d0 | 93 | fi |
8544a6f1 PB |
94 | case "$6" in *7??) mode=+x;; *) mode=-x;; esac |
95 | chmod "$mode" "$4" | |
96 | ||
e2b6a9d0 | 97 | if [ $ret -ne 0 ]; then |
2a68a865 LT |
98 | # Reset the index to the first branch, making |
99 | # git-diff-file useful | |
100 | git-update-cache --add --cacheinfo "$6" "$2" "$4" | |
101 | echo "ERROR: Merge conflict in $4." | |
0a9ea850 JB |
102 | exit 1 |
103 | fi | |
ec73962d PB |
104 | exec git-update-cache --add -- "$4" |
105 | ;; | |
106 | ||
e3b4be7f | 107 | *) |
ec73962d PB |
108 | echo "ERROR: $4: Not handling case $1 -> $2 -> $3" |
109 | ;; | |
e3b4be7f LT |
110 | esac |
111 | exit 1 |