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
)
61 verbosity
="$verbosity -q" ;;
63 verbosity
="$verbosity -v" ;;
65 progress
=--progress ;;
67 progress
=--no-progress ;;
68 -n|
--no-stat|
--no-summary)
74 --no-c|
--no-co|
--no-com|
--no-comm|
--no-commi|
--no-commit)
75 no_commit
=--no-commit ;;
76 --c|
--co|
--com|
--comm|
--commi|
--commit)
78 --sq|
--squ|
--squa|
--squas|
--squash)
80 --no-sq|
--no-squ|
--no-squa|
--no-squas|
--no-squash)
88 -s=*|
--s=*|
--st=*|
--str=*|
--stra=*|
--strat=*|
--strate=*|\
89 --strateg=*|
--strategy=*|\
90 -s|
--s|
--st|
--str|
--stra|
--strat|
--strate|
--strateg|
--strategy)
93 strategy
=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;;
100 strategy_args
="${strategy_args}-s $strategy "
107 xx
="-X $(git rev-parse --sq-quote "$2")"
110 xx
=$
(git rev-parse
--sq-quote "$1") ;;
112 merge_args
="$merge_args$xx "
114 -r|
--r|
--re|
--reb|
--reba|
--rebas|
--rebase)
117 --rebase=i|
--rebase=interactive
)
121 --no-r|
--no-re|
--no-reb|
--no-reba|
--no-rebas|
--no-rebase)
125 --recurse-submodules)
126 recurse_submodules
=--recurse-submodules
128 --recurse-submodules=*)
129 recurse_submodules
="$1"
131 --no-recurse-submodules)
132 recurse_submodules
=--no-recurse-submodules
134 --d|
--dr|
--dry|
--dry-|
--dry-r|
--dry-ru|
--dry-run)
141 # Pass thru anything that may be meant for fetch.
148 error_on_no_merge_candidates
() {
153 -t|
--t|
--ta|
--tag|
--tags)
154 echo "Fetching tags only, you probably meant:"
155 echo " git fetch --tags"
160 if test true
= "$rebase"
169 curr_branch
=${curr_branch#refs/heads/}
170 upstream
=$
(git config
"branch.$curr_branch.merge")
171 remote
=$
(git config
"branch.$curr_branch.remote")
173 if [ $# -gt 1 ]; then
174 if [ "$rebase" = true
]; then
175 printf "There is no candidate for rebasing against "
177 printf "There are no candidates for merging "
179 echo "among the refs that you just fetched."
180 echo "Generally this means that you provided a wildcard refspec which had no"
181 echo "matches on the remote end."
182 elif [ $# -gt 0 ] && [ "$1" != "$remote" ]; then
183 echo "You asked to pull from the remote '$1', but did not specify"
184 echo "a branch. Because this is not the default configured remote"
185 echo "for your current branch, you must specify a branch on the command line."
186 elif [ -z "$curr_branch" -o -z "$upstream" ]; then
188 error_on_missing_default_upstream
"pull" $op_type $op_prep \
189 "git pull <repository> <refspec>"
191 echo "Your configuration specifies to $op_type $op_prep the ref '${upstream#refs/heads/}'"
192 echo "from the remote, but no such ref was fetched."
197 test true
= "$rebase" && {
198 if ! git rev-parse
-q --verify HEAD
>/dev
/null
200 # On an unborn branch
201 if test -f "$GIT_DIR/index"
203 die
"$(gettext "updating an unborn branch with changes added to the index
")"
206 require_clean_work_tree
"pull with rebase" "Please commit or stash them."
209 . git-parse-remote
&&
210 remoteref
="$(get_remote_merge_branch "$@
" 2>/dev/null)" &&
211 oldremoteref
="$(git rev-parse -q --verify "$remoteref")" &&
212 for reflog
in $
(git rev-list
-g $remoteref 2>/dev
/null
)
214 if test "$reflog" = "$(git merge-base $reflog $curr_branch)"
216 oldremoteref
="$reflog"
221 orig_head
=$
(git rev-parse
-q --verify HEAD
)
222 git fetch
$verbosity $progress $dry_run $recurse_submodules --update-head-ok "$@" ||
exit 1
223 test -z "$dry_run" ||
exit 0
225 curr_head
=$
(git rev-parse
-q --verify HEAD
)
226 if test -n "$orig_head" && test "$curr_head" != "$orig_head"
228 # The fetch involved updating the current branch.
230 # The working tree and the index file is still based on the
231 # $orig_head commit, but we are merging into $curr_head.
232 # First update the working tree to match $curr_head.
234 eval_gettextln
"Warning: fetch updated the current branch head.
235 Warning: fast-forwarding your working tree from
236 Warning: commit \$orig_head." >&2
237 git update-index
-q --refresh
238 git read-tree
-u -m "$orig_head" "$curr_head" ||
239 die
"$(eval_gettext "Cannot fast-forward your working tree.
240 After making sure that you saved anything precious from
241 $ git
diff \
$orig_head
248 merge_head
=$
(sed -e '/ not-for-merge /d' \
249 -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \
252 case "$merge_head" in
254 error_on_no_merge_candidates
"$@"
257 if test -z "$orig_head"
259 die
"$(gettext "Cannot merge multiple branches into empty
head")"
261 if test true
= "$rebase"
263 die
"$(gettext "Cannot rebase onto multiple branches
")"
268 if test -z "$orig_head"
270 git update-ref
-m "initial pull" HEAD
$merge_head "$curr_head" &&
271 git read-tree
-m -u HEAD ||
exit 1
275 if test true
= "$rebase"
277 o
=$
(git show-branch
--merge-base $curr_branch $merge_head $oldremoteref)
278 if test "$oldremoteref" = "$o"
284 merge_name
=$
(git fmt-merge-msg
$log_arg <"$GIT_DIR/FETCH_HEAD") ||
exit
287 eval="git-rebase $rebase_options $diffstat $strategy_args $merge_args"
288 eval="$eval --onto $merge_head ${oldremoteref:-$merge_head}"
291 eval="git-merge $diffstat $no_commit $squash $no_ff $ff_only"
292 eval="$eval $log_arg $strategy_args $merge_args $verbosity $progress"
293 eval="$eval \"\$merge_name\" HEAD $merge_head"