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-stat] [--[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.'
13 set_reflog_action
"pull${1+ $*}"
14 require_work_tree_exists
19 git diff-index
--cached --name-status -r --ignore-submodules HEAD
--
20 if [ $
(git config
--bool --get advice.resolveConflict ||
echo true
) = "true" ]; then
21 die
"$(gettext "Pull is not possible because you have unmerged files.
22 Please
, fix them up
in the work tree
, and
then use
'git add/rm <file>'
23 as appropriate to mark resolution
, or use
'git commit -a'.
")"
25 die
"$(gettext "Pull is not possible because you have unmerged files.
")"
30 if [ $
(git config
--bool --get advice.resolveConflict ||
echo true
) = "true" ]; then
31 die
"$(gettext "You have not concluded your merge
(MERGE_HEAD exists
).
32 Please
, commit your changes before you can merge.
")"
34 die
"$(gettext "You have not concluded your merge
(MERGE_HEAD exists
).
")"
38 test -z "$(git ls-files -u)" || die_conflict
39 test -f "$GIT_DIR/MERGE_HEAD" && die_merge
41 strategy_args
= diffstat
= no_commit
= squash
= no_ff
= ff_only
=
42 log_arg
= verbosity
= progress
= recurse_submodules
=
44 curr_branch
=$
(git symbolic-ref
-q HEAD
)
45 curr_branch_short
="${curr_branch#refs/heads/}"
47 case "$(git config branch.$curr_branch_short.rebase)" in
53 rebase
=$
(git config
--bool branch.
$curr_branch_short.rebase
)
58 rebase
=$
(git config
--bool pull.rebase
)
65 verbosity
="$verbosity -q" ;;
67 verbosity
="$verbosity -v" ;;
69 progress
=--progress ;;
71 progress
=--no-progress ;;
72 -n|
--no-stat|
--no-summary)
78 --no-c|
--no-co|
--no-com|
--no-comm|
--no-commi|
--no-commit)
79 no_commit
=--no-commit ;;
80 --c|
--co|
--com|
--comm|
--commi|
--commit)
86 --sq|
--squ|
--squa|
--squas|
--squash)
88 --no-sq|
--no-squ|
--no-squa|
--no-squas|
--no-squash)
96 -s=*|
--s=*|
--st=*|
--str=*|
--stra=*|
--strat=*|
--strate=*|\
97 --strateg=*|
--strategy=*|\
98 -s|
--s|
--st|
--str|
--stra|
--strat|
--strate|
--strateg|
--strategy)
101 strategy
=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;;
108 strategy_args
="${strategy_args}-s $strategy "
115 xx
="-X $(git rev-parse --sq-quote "$2")"
118 xx
=$
(git rev-parse
--sq-quote "$1") ;;
120 merge_args
="$merge_args$xx "
122 -r|
--r|
--re|
--reb|
--reba|
--rebas|
--rebase)
125 --rebase=i|
--rebase=interactive
)
129 --no-r|
--no-re|
--no-reb|
--no-reba|
--no-rebas|
--no-rebase)
133 --recurse-submodules)
134 recurse_submodules
=--recurse-submodules
136 --recurse-submodules=*)
137 recurse_submodules
="$1"
139 --no-recurse-submodules)
140 recurse_submodules
=--no-recurse-submodules
142 --d|
--dr|
--dry|
--dry-|
--dry-r|
--dry-ru|
--dry-run)
149 # Pass thru anything that may be meant for fetch.
156 error_on_no_merge_candidates
() {
161 -t|
--t|
--ta|
--tag|
--tags)
162 echo "Fetching tags only, you probably meant:"
163 echo " git fetch --tags"
168 if test true
= "$rebase"
177 curr_branch
=${curr_branch#refs/heads/}
178 upstream
=$
(git config
"branch.$curr_branch.merge")
179 remote
=$
(git config
"branch.$curr_branch.remote")
181 if [ $# -gt 1 ]; then
182 if [ "$rebase" = true
]; then
183 printf "There is no candidate for rebasing against "
185 printf "There are no candidates for merging "
187 echo "among the refs that you just fetched."
188 echo "Generally this means that you provided a wildcard refspec which had no"
189 echo "matches on the remote end."
190 elif [ $# -gt 0 ] && [ "$1" != "$remote" ]; then
191 echo "You asked to pull from the remote '$1', but did not specify"
192 echo "a branch. Because this is not the default configured remote"
193 echo "for your current branch, you must specify a branch on the command line."
194 elif [ -z "$curr_branch" -o -z "$upstream" ]; then
196 error_on_missing_default_upstream
"pull" $op_type $op_prep \
197 "git pull <remote> <branch>"
199 echo "Your configuration specifies to $op_type $op_prep the ref '${upstream#refs/heads/}'"
200 echo "from the remote, but no such ref was fetched."
205 test true
= "$rebase" && {
206 if ! git rev-parse
-q --verify HEAD
>/dev
/null
208 # On an unborn branch
209 if test -f "$GIT_DIR/index"
211 die
"$(gettext "updating an unborn branch with changes added to the index
")"
214 require_clean_work_tree
"pull with rebase" "Please commit or stash them."
217 . git-parse-remote
&&
218 remoteref
="$(get_remote_merge_branch "$@
" 2>/dev/null)" &&
219 oldremoteref
="$(git rev-parse -q --verify "$remoteref")" &&
220 for reflog
in $
(git rev-list
-g $remoteref 2>/dev
/null
)
222 if test "$reflog" = "$(git merge-base $reflog $curr_branch)"
224 oldremoteref
="$reflog"
229 orig_head
=$
(git rev-parse
-q --verify HEAD
)
230 git fetch
$verbosity $progress $dry_run $recurse_submodules --update-head-ok "$@" ||
exit 1
231 test -z "$dry_run" ||
exit 0
233 curr_head
=$
(git rev-parse
-q --verify HEAD
)
234 if test -n "$orig_head" && test "$curr_head" != "$orig_head"
236 # The fetch involved updating the current branch.
238 # The working tree and the index file is still based on the
239 # $orig_head commit, but we are merging into $curr_head.
240 # First update the working tree to match $curr_head.
242 eval_gettextln
"Warning: fetch updated the current branch head.
243 Warning: fast-forwarding your working tree from
244 Warning: commit \$orig_head." >&2
245 git update-index
-q --refresh
246 git read-tree
-u -m "$orig_head" "$curr_head" ||
247 die
"$(eval_gettext "Cannot fast-forward your working tree.
248 After making sure that you saved anything precious from
249 $ git
diff \
$orig_head
256 merge_head
=$
(sed -e '/ not-for-merge /d' \
257 -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \
260 case "$merge_head" in
262 error_on_no_merge_candidates
"$@"
265 if test -z "$orig_head"
267 die
"$(gettext "Cannot merge multiple branches into empty
head")"
269 if test true
= "$rebase"
271 die
"$(gettext "Cannot rebase onto multiple branches
")"
276 if test -z "$orig_head"
278 git update-ref
-m "initial pull" HEAD
$merge_head "$curr_head" &&
279 git read-tree
-m -u HEAD ||
exit 1
283 if test true
= "$rebase"
285 o
=$
(git show-branch
--merge-base $curr_branch $merge_head $oldremoteref)
286 if test "$oldremoteref" = "$o"
292 merge_name
=$
(git fmt-merge-msg
$log_arg <"$GIT_DIR/FETCH_HEAD") ||
exit
295 eval="git-rebase $rebase_options $diffstat $strategy_args $merge_args"
296 eval="$eval --onto $merge_head ${oldremoteref:-$merge_head}"
299 eval="git-merge $diffstat $no_commit $edit $squash $no_ff $ff_only"
300 eval="$eval $log_arg $strategy_args $merge_args $verbosity $progress"
301 eval="$eval \"\$merge_name\" HEAD $merge_head"