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