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] [--[no-]rebase|--rebase=preserve] [-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 bool_or_string_config
() {
42 git config
--bool "$1" 2>/dev
/null || git config
"$1"
45 strategy_args
= diffstat
= no_commit
= squash
= no_ff
= ff_only
=
46 log_arg
= verbosity
= progress
= recurse_submodules
= verify_signatures
=
47 merge_args
= edit
= rebase_args
=
48 curr_branch
=$
(git symbolic-ref
-q HEAD
)
49 curr_branch_short
="${curr_branch#refs/heads/}"
50 rebase
=$
(bool_or_string_config branch.
$curr_branch_short.rebase
)
53 rebase
=$
(bool_or_string_config pull.rebase
)
60 verbosity
="$verbosity -q" ;;
62 verbosity
="$verbosity -v" ;;
64 progress
=--progress ;;
66 progress
=--no-progress ;;
67 -n|
--no-stat|
--no-summary)
73 --no-c|
--no-co|
--no-com|
--no-comm|
--no-commi|
--no-commit)
74 no_commit
=--no-commit ;;
75 --c|
--co|
--com|
--comm|
--commi|
--commit)
81 --sq|
--squ|
--squa|
--squas|
--squash)
83 --no-sq|
--no-squ|
--no-squa|
--no-squas|
--no-squash)
91 -s=*|
--s=*|
--st=*|
--str=*|
--stra=*|
--strat=*|
--strate=*|\
92 --strateg=*|
--strategy=*|\
93 -s|
--s|
--st|
--str|
--stra|
--strat|
--strate|
--strateg|
--strategy)
96 strategy
=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;;
103 strategy_args
="${strategy_args}-s $strategy "
110 xx
="-X $(git rev-parse --sq-quote "$2")"
113 xx
=$
(git rev-parse
--sq-quote "$1") ;;
115 merge_args
="$merge_args$xx "
117 -r=*|
--r=*|
--re=*|
--reb=*|
--reba=*|
--rebas=*|
--rebase=*)
120 -r|
--r|
--re|
--reb|
--reba|
--rebas|
--rebase)
123 --no-r|
--no-re|
--no-reb|
--no-reba|
--no-rebas|
--no-rebase)
126 --recurse-submodules)
127 recurse_submodules
=--recurse-submodules
129 --recurse-submodules=*)
130 recurse_submodules
="$1"
132 --no-recurse-submodules)
133 recurse_submodules
=--no-recurse-submodules
136 verify_signatures
=--verify-signatures
138 --no-verify-signatures)
139 verify_signatures
=--no-verify-signatures
141 --d|
--dr|
--dry|
--dry-|
--dry-r|
--dry-ru|
--dry-run)
148 # Pass thru anything that may be meant for fetch.
158 rebase_args
=--preserve-merges
163 echo "Invalid value for --rebase, should be true, false, or preserve"
169 error_on_no_merge_candidates
() {
174 -t|
--t|
--ta|
--tag|
--tags)
175 echo "It doesn't make sense to pull all tags; you probably meant:"
176 echo " git fetch --tags"
181 if test true
= "$rebase"
190 upstream
=$
(git config
"branch.$curr_branch_short.merge")
191 remote
=$
(git config
"branch.$curr_branch_short.remote")
193 if [ $# -gt 1 ]; then
194 if [ "$rebase" = true
]; then
195 printf "There is no candidate for rebasing against "
197 printf "There are no candidates for merging "
199 echo "among the refs that you just fetched."
200 echo "Generally this means that you provided a wildcard refspec which had no"
201 echo "matches on the remote end."
202 elif [ $# -gt 0 ] && [ "$1" != "$remote" ]; then
203 echo "You asked to pull from the remote '$1', but did not specify"
204 echo "a branch. Because this is not the default configured remote"
205 echo "for your current branch, you must specify a branch on the command line."
206 elif [ -z "$curr_branch" -o -z "$upstream" ]; then
208 error_on_missing_default_upstream
"pull" $op_type $op_prep \
209 "git pull <remote> <branch>"
211 echo "Your configuration specifies to $op_type $op_prep the ref '${upstream#refs/heads/}'"
212 echo "from the remote, but no such ref was fetched."
217 test true
= "$rebase" && {
218 if ! git rev-parse
-q --verify HEAD
>/dev
/null
220 # On an unborn branch
221 if test -f "$GIT_DIR/index"
223 die
"$(gettext "updating an unborn branch with changes added to the index
")"
226 require_clean_work_tree
"pull with rebase" "Please commit or stash them."
229 test -n "$curr_branch" &&
230 . git-parse-remote
&&
231 remoteref
="$(get_remote_merge_branch "$@
" 2>/dev/null)" &&
232 oldremoteref
="$(git rev-parse -q --verify "$remoteref")" &&
233 for reflog
in $
(git rev-list
-g $remoteref 2>/dev
/null
)
235 if test "$reflog" = "$(git merge-base $reflog $curr_branch)"
237 oldremoteref
="$reflog"
242 orig_head
=$
(git rev-parse
-q --verify HEAD
)
243 git fetch
$verbosity $progress $dry_run $recurse_submodules --update-head-ok "$@" ||
exit 1
244 test -z "$dry_run" ||
exit 0
246 curr_head
=$
(git rev-parse
-q --verify HEAD
)
247 if test -n "$orig_head" && test "$curr_head" != "$orig_head"
249 # The fetch involved updating the current branch.
251 # The working tree and the index file is still based on the
252 # $orig_head commit, but we are merging into $curr_head.
253 # First update the working tree to match $curr_head.
255 eval_gettextln
"Warning: fetch updated the current branch head.
256 Warning: fast-forwarding your working tree from
257 Warning: commit \$orig_head." >&2
258 git update-index
-q --refresh
259 git read-tree
-u -m "$orig_head" "$curr_head" ||
260 die
"$(eval_gettext "Cannot fast-forward your working tree.
261 After making sure that you saved anything precious from
262 $ git
diff \
$orig_head
269 merge_head
=$
(sed -e '/ not-for-merge /d' \
270 -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \
273 case "$merge_head" in
275 error_on_no_merge_candidates
"$@"
278 if test -z "$orig_head"
280 die
"$(gettext "Cannot merge multiple branches into empty
head")"
282 if test true
= "$rebase"
284 die
"$(gettext "Cannot rebase onto multiple branches
")"
289 # Pulling into unborn branch: a shorthand for branching off
290 # FETCH_HEAD, for lazy typers.
291 if test -z "$orig_head"
293 # Two-way merge: we claim the index is based on an empty tree,
294 # and try to fast-forward to HEAD. This ensures we will not
295 # lose index/worktree changes that the user already made on
297 empty_tree
=4b825dc642cb6eb9a060e54bf8d69288fbee4904
298 git read-tree
-m -u $empty_tree $merge_head &&
299 git update-ref
-m "initial pull" HEAD
$merge_head "$curr_head"
303 if test true
= "$rebase"
305 o
=$
(git show-branch
--merge-base $curr_branch $merge_head $oldremoteref)
306 if test "$oldremoteref" = "$o"
312 merge_name
=$
(git fmt-merge-msg
$log_arg <"$GIT_DIR/FETCH_HEAD") ||
exit
315 eval="git-rebase $diffstat $strategy_args $merge_args $rebase_args $verbosity"
316 eval="$eval --onto $merge_head ${oldremoteref:-$merge_head}"
319 eval="git-merge $diffstat $no_commit $verify_signatures $edit $squash $no_ff $ff_only"
320 eval="$eval $log_arg $strategy_args $merge_args $verbosity $progress"
321 eval="$eval \"\$merge_name\" HEAD $merge_head"