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