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 integrate it/them with 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
= verify_signatures
=
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
143 verify_signatures
=--verify-signatures
145 --no-verify-signatures)
146 verify_signatures
=--no-verify-signatures
148 --d|
--dr|
--dry|
--dry-|
--dry-r|
--dry-ru|
--dry-run)
155 # Pass thru anything that may be meant for fetch.
162 error_on_no_merge_candidates
() {
167 -t|
--t|
--ta|
--tag|
--tags)
168 echo "Fetching tags only, you probably meant:"
169 echo " git fetch --tags"
174 if test true
= "$rebase"
183 curr_branch
=${curr_branch#refs/heads/}
184 upstream
=$
(git config
"branch.$curr_branch.merge")
185 remote
=$
(git config
"branch.$curr_branch.remote")
187 if [ $# -gt 1 ]; then
188 if [ "$rebase" = true
]; then
189 printf "There is no candidate for rebasing against "
191 printf "There are no candidates for merging "
193 echo "among the refs that you just fetched."
194 echo "Generally this means that you provided a wildcard refspec which had no"
195 echo "matches on the remote end."
196 elif [ $# -gt 0 ] && [ "$1" != "$remote" ]; then
197 echo "You asked to pull from the remote '$1', but did not specify"
198 echo "a branch. Because this is not the default configured remote"
199 echo "for your current branch, you must specify a branch on the command line."
200 elif [ -z "$curr_branch" -o -z "$upstream" ]; then
202 error_on_missing_default_upstream
"pull" $op_type $op_prep \
203 "git pull <remote> <branch>"
205 echo "Your configuration specifies to $op_type $op_prep the ref '${upstream#refs/heads/}'"
206 echo "from the remote, but no such ref was fetched."
211 test true
= "$rebase" && {
212 if ! git rev-parse
-q --verify HEAD
>/dev
/null
214 # On an unborn branch
215 if test -f "$GIT_DIR/index"
217 die
"$(gettext "updating an unborn branch with changes added to the index
")"
220 require_clean_work_tree
"pull with rebase" "Please commit or stash them."
223 test -n "$curr_branch" &&
224 . git-parse-remote
&&
225 remoteref
="$(get_remote_merge_branch "$@
" 2>/dev/null)" &&
226 oldremoteref
="$(git rev-parse -q --verify "$remoteref")" &&
227 for reflog
in $
(git rev-list
-g $remoteref 2>/dev
/null
)
229 if test "$reflog" = "$(git merge-base $reflog $curr_branch)"
231 oldremoteref
="$reflog"
236 orig_head
=$
(git rev-parse
-q --verify HEAD
)
237 git fetch
$verbosity $progress $dry_run $recurse_submodules --update-head-ok "$@" ||
exit 1
238 test -z "$dry_run" ||
exit 0
240 curr_head
=$
(git rev-parse
-q --verify HEAD
)
241 if test -n "$orig_head" && test "$curr_head" != "$orig_head"
243 # The fetch involved updating the current branch.
245 # The working tree and the index file is still based on the
246 # $orig_head commit, but we are merging into $curr_head.
247 # First update the working tree to match $curr_head.
249 eval_gettextln
"Warning: fetch updated the current branch head.
250 Warning: fast-forwarding your working tree from
251 Warning: commit \$orig_head." >&2
252 git update-index
-q --refresh
253 git read-tree
-u -m "$orig_head" "$curr_head" ||
254 die
"$(eval_gettext "Cannot fast-forward your working tree.
255 After making sure that you saved anything precious from
256 $ git
diff \
$orig_head
263 merge_head
=$
(sed -e '/ not-for-merge /d' \
264 -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \
267 case "$merge_head" in
269 error_on_no_merge_candidates
"$@"
272 if test -z "$orig_head"
274 die
"$(gettext "Cannot merge multiple branches into empty
head")"
276 if test true
= "$rebase"
278 die
"$(gettext "Cannot rebase onto multiple branches
")"
283 # Pulling into unborn branch: a shorthand for branching off
284 # FETCH_HEAD, for lazy typers.
285 if test -z "$orig_head"
287 # Two-way merge: we claim the index is based on an empty tree,
288 # and try to fast-forward to HEAD. This ensures we will not
289 # lose index/worktree changes that the user already made on
291 empty_tree
=4b825dc642cb6eb9a060e54bf8d69288fbee4904
292 git read-tree
-m -u $empty_tree $merge_head &&
293 git update-ref
-m "initial pull" HEAD
$merge_head "$curr_head"
297 if test true
= "$rebase"
299 o
=$
(git show-branch
--merge-base $curr_branch $merge_head $oldremoteref)
300 if test "$oldremoteref" = "$o"
306 merge_name
=$
(git fmt-merge-msg
$log_arg <"$GIT_DIR/FETCH_HEAD") ||
exit
309 eval="git-rebase $rebase_options $diffstat $strategy_args $merge_args $verbosity"
310 eval="$eval --onto $merge_head ${oldremoteref:-$merge_head}"
313 eval="git-merge $diffstat $no_commit $verify_signatures $edit $squash $no_ff $ff_only"
314 eval="$eval $log_arg $strategy_args $merge_args $verbosity $progress"
315 eval="$eval \"\$merge_name\" HEAD $merge_head"