]>
Commit | Line | Data |
---|---|---|
839a7a06 LT |
1 | #!/bin/sh |
2 | # | |
521003ff JH |
3 | # Copyright (c) 2005 Junio C Hamano |
4 | # | |
5 | # Fetch one or more remote refs and merge it/them into the current HEAD. | |
6 | ||
806f36d4 FK |
7 | USAGE='[-n | --no-summary] [--no-commit] [-s strategy]... [<fetch-options>] <repo> <head>...' |
8 | LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEAD.' | |
ae2b0f15 | 9 | . git-sh-setup |
b10ac50f | 10 | |
7d0c6887 | 11 | strategy_args= no_summary= no_commit= squash= |
60fb5b2c JH |
12 | while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac |
13 | do | |
14 | case "$1" in | |
15 | -n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\ | |
16 | --no-summa|--no-summar|--no-summary) | |
17 | no_summary=-n ;; | |
123ee3ca JH |
18 | --no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit) |
19 | no_commit=--no-commit ;; | |
7d0c6887 JH |
20 | --sq|--squ|--squa|--squas|--squash) |
21 | squash=--squash ;; | |
60fb5b2c JH |
22 | -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\ |
23 | --strateg=*|--strategy=*|\ | |
24 | -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy) | |
25 | case "$#,$1" in | |
26 | *,*=*) | |
8096fae7 | 27 | strategy=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;; |
60fb5b2c JH |
28 | 1,*) |
29 | usage ;; | |
30 | *) | |
31 | strategy="$2" | |
32 | shift ;; | |
33 | esac | |
34 | strategy_args="${strategy_args}-s $strategy " | |
35 | ;; | |
93d69d86 JL |
36 | -h|--h|--he|--hel|--help) |
37 | usage | |
38 | ;; | |
60fb5b2c | 39 | -*) |
619e5a0e JH |
40 | # Pass thru anything that is meant for fetch. |
41 | break | |
60fb5b2c JH |
42 | ;; |
43 | esac | |
44 | shift | |
45 | done | |
46 | ||
d09e79cb | 47 | orig_head=$(git-rev-parse --verify HEAD 2>/dev/null) |
55b7835e | 48 | git-fetch --update-head-ok --reflog-action=pull "$@" || exit 1 |
b10ac50f | 49 | |
d09e79cb | 50 | curr_head=$(git-rev-parse --verify HEAD 2>/dev/null) |
b10ac50f JH |
51 | if test "$curr_head" != "$orig_head" |
52 | then | |
53 | # The fetch involved updating the current branch. | |
54 | ||
55 | # The working tree and the index file is still based on the | |
56 | # $orig_head commit, but we are merging into $curr_head. | |
57 | # First update the working tree to match $curr_head. | |
58 | ||
59 | echo >&2 "Warning: fetch updated the current branch head." | |
cf46e7b8 | 60 | echo >&2 "Warning: fast forwarding your working tree from" |
a057f806 | 61 | echo >&2 "Warning: commit $orig_head." |
cf46e7b8 | 62 | git-update-index --refresh 2>/dev/null |
b10ac50f | 63 | git-read-tree -u -m "$orig_head" "$curr_head" || |
8323124a JH |
64 | die 'Cannot fast-forward your working tree. |
65 | After making sure that you saved anything precious from | |
66 | $ git diff '$orig_head' | |
67 | output, run | |
68 | $ git reset --hard | |
69 | to recover.' | |
70 | ||
b10ac50f JH |
71 | fi |
72 | ||
05dd8e2e JH |
73 | merge_head=$(sed -e '/ not-for-merge /d' \ |
74 | -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \ | |
75 | tr '\012' ' ') | |
e0bfc81e JH |
76 | |
77 | case "$merge_head" in | |
521003ff | 78 | '') |
4363dfbe JW |
79 | curr_branch=$(git-symbolic-ref HEAD | \ |
80 | sed -e 's|^refs/heads/||') | |
81 | echo >&2 "Warning: No merge candidate found because value of config option | |
82 | \"branch.${curr_branch}.merge\" does not match any remote branch fetched." | |
521003ff JH |
83 | echo >&2 "No changes." |
84 | exit 0 | |
85 | ;; | |
60fb5b2c | 86 | ?*' '?*) |
d09e79cb LT |
87 | if test -z "$orig_head" |
88 | then | |
89 | echo >&2 "Cannot merge multiple branches into empty head" | |
90 | exit 1 | |
91 | fi | |
f5ef535f | 92 | var=`git-repo-config --get pull.octopus` |
c8e2db00 | 93 | if test -n "$var" |
a1c29295 | 94 | then |
4890f62b | 95 | strategy_default_args="-s $var" |
a1c29295 | 96 | fi |
60fb5b2c JH |
97 | ;; |
98 | *) | |
f5ef535f | 99 | var=`git-repo-config --get pull.twohead` |
c8e2db00 MH |
100 | if test -n "$var" |
101 | then | |
4890f62b | 102 | strategy_default_args="-s $var" |
a1c29295 | 103 | fi |
60fb5b2c JH |
104 | ;; |
105 | esac | |
106 | ||
d09e79cb LT |
107 | if test -z "$orig_head" |
108 | then | |
109 | git-update-ref -m "initial pull" HEAD $merge_head "" && | |
110 | git-read-tree --reset -u HEAD || exit 1 | |
111 | exit | |
112 | fi | |
113 | ||
60fb5b2c JH |
114 | case "$strategy_args" in |
115 | '') | |
116 | strategy_args=$strategy_default_args | |
acfadcfb | 117 | ;; |
e0bfc81e JH |
118 | esac |
119 | ||
86378b32 | 120 | merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD") || exit |
e1447e38 SP |
121 | git-merge "--reflog-action=pull $*" \ |
122 | $no_summary $no_commit $squash $strategy_args \ | |
7d0c6887 | 123 | "$merge_name" HEAD $merge_head |