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-summary] [--[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.'
12 set_reflog_action
"pull $*"
16 test -z "$(git ls-files -u)" ||
17 die
"You are in the middle of a conflicted merge."
19 strategy_args
= no_summary
= no_commit
= squash
= no_ff
=
23 -n|
--n|
--no|
--no-|
--no-s|
--no-su|
--no-sum|
--no-summ|\
24 --no-summa|
--no-summar|
--no-summary)
29 --no-c|
--no-co|
--no-com|
--no-comm|
--no-commi|
--no-commit)
30 no_commit
=--no-commit ;;
31 --c|
--co|
--com|
--comm|
--commi|
--commit)
33 --sq|
--squ|
--squa|
--squas|
--squash)
35 --no-sq|
--no-squ|
--no-squa|
--no-squas|
--no-squash)
41 -s=*|
--s=*|
--st=*|
--str=*|
--stra=*|
--strat=*|
--strate=*|\
42 --strateg=*|
--strategy=*|\
43 -s|
--s|
--st|
--str|
--stra|
--strat|
--strate|
--strateg|
--strategy)
46 strategy
=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;;
53 strategy_args
="${strategy_args}-s $strategy "
55 -h|
--h|
--he|
--hel|
--help)
59 # Pass thru anything that may be meant for fetch.
66 orig_head
=$
(git rev-parse
--verify HEAD
2>/dev
/null
)
67 git-fetch
--update-head-ok "$@" ||
exit 1
69 curr_head
=$
(git rev-parse
--verify HEAD
2>/dev
/null
)
70 if test "$curr_head" != "$orig_head"
72 # The fetch involved updating the current branch.
74 # The working tree and the index file is still based on the
75 # $orig_head commit, but we are merging into $curr_head.
76 # First update the working tree to match $curr_head.
78 echo >&2 "Warning: fetch updated the current branch head."
79 echo >&2 "Warning: fast forwarding your working tree from"
80 echo >&2 "Warning: commit $orig_head."
81 git update-index
--refresh 2>/dev
/null
82 git read-tree
-u -m "$orig_head" "$curr_head" ||
83 die
'Cannot fast-forward your working tree.
84 After making sure that you saved anything precious from
85 $ git diff '$orig_head'
92 merge_head
=$
(sed -e '/ not-for-merge /d' \
93 -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \
98 curr_branch
=$
(git symbolic-ref
-q HEAD
)
101 1) echo >&2 "You are not currently on a branch; you must explicitly"
102 echo >&2 "specify which branch you wish to merge:"
103 echo >&2 " git pull <remote> <branch>"
107 curr_branch
=${curr_branch#refs/heads/}
109 echo >&2 "You asked me to pull without telling me which branch you"
110 echo >&2 "want to merge with, and 'branch.${curr_branch}.merge' in"
111 echo >&2 "your configuration file does not tell me either. Please"
112 echo >&2 "name which branch you want to merge on the command line and"
113 echo >&2 "try again (e.g. 'git pull <repository> <refspec>')."
114 echo >&2 "See git-pull(1) for details on the refspec."
116 echo >&2 "If you often merge with the same branch, you may want to"
117 echo >&2 "configure the following variables in your configuration"
120 echo >&2 " branch.${curr_branch}.remote = <nickname>"
121 echo >&2 " branch.${curr_branch}.merge = <remote-ref>"
122 echo >&2 " remote.<nickname>.url = <url>"
123 echo >&2 " remote.<nickname>.fetch = <refspec>"
125 echo >&2 "See git-config(1) for details."
129 if test -z "$orig_head"
131 echo >&2 "Cannot merge multiple branches into empty head"
137 if test -z "$orig_head"
139 git update-ref
-m "initial pull" HEAD
$merge_head "" &&
140 git read-tree
--reset -u HEAD ||
exit 1
144 merge_name
=$
(git fmt-merge-msg
<"$GIT_DIR/FETCH_HEAD") ||
exit
145 exec git-merge
$no_summary $no_commit $squash $no_ff $strategy_args \
146 "$merge_name" HEAD
$merge_head