3 # Copyright (c) 2005 Junio C Hamano
5 # Fetch one or more remote refs and merge it/them into the current HEAD.
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.'
10 set_reflog_action "pull $*"
12 strategy_args= no_summary= no_commit= squash=
13 while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
16 -n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
17 --no-summa|--no-summar|--no-summary)
19 --no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
20 no_commit=--no-commit ;;
21 --sq|--squ|--squa|--squas|--squash)
23 -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
24 --strateg=*|--strategy=*|\
25 -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
28 strategy=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;;
35 strategy_args="${strategy_args}-s $strategy "
37 -h|--h|--he|--hel|--help)
41 # Pass thru anything that is meant for fetch.
48 orig_head=$(git-rev-parse --verify HEAD 2>/dev/null)
49 git-fetch --update-head-ok "$@" || exit 1
51 curr_head=$(git-rev-parse --verify HEAD 2>/dev/null)
52 if test "$curr_head" != "$orig_head"
54 # The fetch involved updating the current branch.
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.
60 echo >&2 "Warning: fetch updated the current branch head."
61 echo >&2 "Warning: fast forwarding your working tree from"
62 echo >&2 "Warning: commit $orig_head."
63 git-update-index --refresh 2>/dev/null
64 git-read-tree -u -m "$orig_head" "$curr_head" ||
65 die 'Cannot fast-forward your working tree.
66 After making sure that you saved anything precious from
67 $ git diff '$orig_head'
74 merge_head=$(sed -e '/ not-for-merge /d' \
75 -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \
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."
84 echo >&2 "No changes."
88 if test -z "$orig_head"
90 echo >&2 "Cannot merge multiple branches into empty head"
93 var=`git-repo-config --get pull.octopus`
96 strategy_default_args="-s $var"
100 var=`git-repo-config --get pull.twohead`
103 strategy_default_args="-s $var"
108 if test -z "$orig_head"
110 git-update-ref -m "initial pull" HEAD $merge_head "" &&
111 git-read-tree --reset -u HEAD || exit 1
115 case "$strategy_args" in
117 strategy_args=$strategy_default_args
121 merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD") || exit
122 exec git-merge $no_summary $no_commit $squash $strategy_args \
123 "$merge_name" HEAD $merge_head