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/}"
46 rebase
=$
(git config
--bool branch.
$curr_branch_short.rebase
)
49 rebase
=$
(git config
--bool pull.rebase
)
56 verbosity
="$verbosity -q" ;;
58 verbosity
="$verbosity -v" ;;
60 progress
=--progress ;;
62 progress
=--no-progress ;;
63 -n|
--no-stat|
--no-summary)
69 --no-c|
--no-co|
--no-com|
--no-comm|
--no-commi|
--no-commit)
70 no_commit
=--no-commit ;;
71 --c|
--co|
--com|
--comm|
--commi|
--commit)
73 --sq|
--squ|
--squa|
--squas|
--squash)
75 --no-sq|
--no-squ|
--no-squa|
--no-squas|
--no-squash)
83 -s=*|
--s=*|
--st=*|
--str=*|
--stra=*|
--strat=*|
--strate=*|\
84 --strateg=*|
--strategy=*|\
85 -s|
--s|
--st|
--str|
--stra|
--strat|
--strate|
--strateg|
--strategy)
88 strategy
=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;;
95 strategy_args
="${strategy_args}-s $strategy "
102 xx
="-X $(git rev-parse --sq-quote "$2")"
105 xx
=$
(git rev-parse
--sq-quote "$1") ;;
107 merge_args
="$merge_args$xx "
109 -r|
--r|
--re|
--reb|
--reba|
--rebas|
--rebase)
112 --no-r|
--no-re|
--no-reb|
--no-reba|
--no-rebas|
--no-rebase)
115 --recurse-submodules)
116 recurse_submodules
=--recurse-submodules
118 --recurse-submodules=*)
119 recurse_submodules
="$1"
121 --no-recurse-submodules)
122 recurse_submodules
=--no-recurse-submodules
124 --d|
--dr|
--dry|
--dry-|
--dry-r|
--dry-ru|
--dry-run)
131 # Pass thru anything that may be meant for fetch.
138 error_on_no_merge_candidates
() {
143 -t|
--t|
--ta|
--tag|
--tags)
144 echo "Fetching tags only, you probably meant:"
145 echo " git fetch --tags"
150 if test true
= "$rebase"
159 curr_branch
=${curr_branch#refs/heads/}
160 upstream
=$
(git config
"branch.$curr_branch.merge")
161 remote
=$
(git config
"branch.$curr_branch.remote")
163 if [ $# -gt 1 ]; then
164 if [ "$rebase" = true
]; then
165 printf "There is no candidate for rebasing against "
167 printf "There are no candidates for merging "
169 echo "among the refs that you just fetched."
170 echo "Generally this means that you provided a wildcard refspec which had no"
171 echo "matches on the remote end."
172 elif [ $# -gt 0 ] && [ "$1" != "$remote" ]; then
173 echo "You asked to pull from the remote '$1', but did not specify"
174 echo "a branch. Because this is not the default configured remote"
175 echo "for your current branch, you must specify a branch on the command line."
176 elif [ -z "$curr_branch" -o -z "$upstream" ]; then
178 error_on_missing_default_upstream
"pull" $op_type $op_prep \
179 "git pull <repository> <refspec>"
181 echo "Your configuration specifies to $op_type $op_prep the ref '${upstream#refs/heads/}'"
182 echo "from the remote, but no such ref was fetched."
187 test true
= "$rebase" && {
188 if ! git rev-parse
-q --verify HEAD
>/dev
/null
190 # On an unborn branch
191 if test -f "$GIT_DIR/index"
193 die
"$(gettext "updating an unborn branch with changes added to the index
")"
196 require_clean_work_tree
"pull with rebase" "Please commit or stash them."
199 . git-parse-remote
&&
200 remoteref
="$(get_remote_merge_branch "$@
" 2>/dev/null)" &&
201 oldremoteref
="$(git rev-parse -q --verify "$remoteref")" &&
202 for reflog
in $
(git rev-list
-g $remoteref 2>/dev
/null
)
204 if test "$reflog" = "$(git merge-base $reflog $curr_branch)"
206 oldremoteref
="$reflog"
211 orig_head
=$
(git rev-parse
-q --verify HEAD
)
212 git fetch
$verbosity $progress $dry_run $recurse_submodules --update-head-ok "$@" ||
exit 1
213 test -z "$dry_run" ||
exit 0
215 curr_head
=$
(git rev-parse
-q --verify HEAD
)
216 if test -n "$orig_head" && test "$curr_head" != "$orig_head"
218 # The fetch involved updating the current branch.
220 # The working tree and the index file is still based on the
221 # $orig_head commit, but we are merging into $curr_head.
222 # First update the working tree to match $curr_head.
224 eval_gettextln
"Warning: fetch updated the current branch head.
225 Warning: fast-forwarding your working tree from
226 Warning: commit \$orig_head." >&2
227 git update-index
-q --refresh
228 git read-tree
-u -m "$orig_head" "$curr_head" ||
229 die
"$(eval_gettext "Cannot fast-forward your working tree.
230 After making sure that you saved anything precious from
231 $ git
diff \
$orig_head
238 merge_head
=$
(sed -e '/ not-for-merge /d' \
239 -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \
242 case "$merge_head" in
244 error_on_no_merge_candidates
"$@"
247 if test -z "$orig_head"
249 die
"$(gettext "Cannot merge multiple branches into empty
head")"
251 if test true
= "$rebase"
253 die
"$(gettext "Cannot rebase onto multiple branches
")"
258 if test -z "$orig_head"
260 git update-ref
-m "initial pull" HEAD
$merge_head "$curr_head" &&
261 git read-tree
-m -u HEAD ||
exit 1
265 if test true
= "$rebase"
267 o
=$
(git show-branch
--merge-base $curr_branch $merge_head $oldremoteref)
268 if test "$oldremoteref" = "$o"
274 merge_name
=$
(git fmt-merge-msg
$log_arg <"$GIT_DIR/FETCH_HEAD") ||
exit
277 eval="git-rebase $diffstat $strategy_args $merge_args"
278 eval="$eval --onto $merge_head ${oldremoteref:-$merge_head}"
281 eval="git-merge $diffstat $no_commit $squash $no_ff $ff_only"
282 eval="$eval $log_arg $strategy_args $merge_args $verbosity $progress"
283 eval="$eval \"\$merge_name\" HEAD $merge_head"