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] [--[no-]squash] [--[no-]ff] [-s strategy]... [<fetch-options>] <repo> <head>...'
8 LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEAD.'
11 set_reflog_action "pull $*"
15 test -z "$(git ls-files -u)" ||
16 die "You are in the middle of a conflicted merge."
18 strategy_args= no_summary= no_commit= squash= no_ff=
22 -n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
23 --no-summa|--no-summar|--no-summary)
28 --no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
29 no_commit=--no-commit ;;
30 --c|--co|--com|--comm|--commi|--commit)
32 --sq|--squ|--squa|--squas|--squash)
34 --no-sq|--no-squ|--no-squa|--no-squas|--no-squash)
40 -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
41 --strateg=*|--strategy=*|\
42 -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
45 strategy=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;;
52 strategy_args="${strategy_args}-s $strategy "
54 -h|--h|--he|--hel|--help)
58 # Pass thru anything that may be meant for fetch.
65 orig_head=$(git rev-parse --verify HEAD 2>/dev/null)
66 git-fetch --update-head-ok "$@" || exit 1
68 curr_head=$(git rev-parse --verify HEAD 2>/dev/null)
69 if test "$curr_head" != "$orig_head"
71 # The fetch involved updating the current branch.
73 # The working tree and the index file is still based on the
74 # $orig_head commit, but we are merging into $curr_head.
75 # First update the working tree to match $curr_head.
77 echo >&2 "Warning: fetch updated the current branch head."
78 echo >&2 "Warning: fast forwarding your working tree from"
79 echo >&2 "Warning: commit $orig_head."
80 git update-index --refresh 2>/dev/null
81 git read-tree -u -m "$orig_head" "$curr_head" ||
82 die 'Cannot fast-forward your working tree.
83 After making sure that you saved anything precious from
84 $ git diff '$orig_head'
91 merge_head=$(sed -e '/ not-for-merge /d' \
92 -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \
97 curr_branch=$(git symbolic-ref -q HEAD)
100 1) echo >&2 "You are not currently on a branch; you must explicitly"
101 echo >&2 "specify which branch you wish to merge:"
102 echo >&2 " git pull <remote> <branch>"
106 curr_branch=${curr_branch#refs/heads/}
108 echo >&2 "You asked me to pull without telling me which branch you"
109 echo >&2 "want to merge with, and 'branch.${curr_branch}.merge' in"
110 echo >&2 "your configuration file does not tell me either. Please"
111 echo >&2 "name which branch you want to merge on the command line and"
112 echo >&2 "try again (e.g. 'git pull <repository> <refspec>')."
113 echo >&2 "See git-pull(1) for details on the refspec."
115 echo >&2 "If you often merge with the same branch, you may want to"
116 echo >&2 "configure the following variables in your configuration"
119 echo >&2 " branch.${curr_branch}.remote = <nickname>"
120 echo >&2 " branch.${curr_branch}.merge = <remote-ref>"
121 echo >&2 " remote.<nickname>.url = <url>"
122 echo >&2 " remote.<nickname>.fetch = <refspec>"
124 echo >&2 "See git-config(1) for details."
128 if test -z "$orig_head"
130 echo >&2 "Cannot merge multiple branches into empty head"
136 if test -z "$orig_head"
138 git update-ref -m "initial pull" HEAD $merge_head "" &&
139 git read-tree --reset -u HEAD || exit 1
143 merge_name=$(git fmt-merge-msg <"$GIT_DIR/FETCH_HEAD") || exit
144 exec git-merge $no_summary $no_commit $squash $no_ff $strategy_args \
145 "$merge_name" HEAD $merge_head