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] [-s strategy]... [<fetch-options>] <repo> <head>...'
8 LONG_USAGE
='Fetch one or more remote refs and merge it/them into the current HEAD.'
11 set_reflog_action
"pull $*"
15 test -z "$(git ls-files -u)" ||
16 die
"You are in the middle of a conflicted merge."
18 strategy_args
= no_summary
= no_commit
= squash
=
22 -n|
--n|
--no|
--no-|
--no-s|
--no-su|
--no-sum|
--no-summ|\
23 --no-summa|
--no-summar|
--no-summary)
28 --no-c|
--no-co|
--no-com|
--no-comm|
--no-commi|
--no-commit)
29 no_commit
=--no-commit ;;
30 --sq|
--squ|
--squa|
--squas|
--squash)
32 -s=*|
--s=*|
--st=*|
--str=*|
--stra=*|
--strat=*|
--strate=*|\
33 --strateg=*|
--strategy=*|\
34 -s|
--s|
--st|
--str|
--stra|
--strat|
--strate|
--strateg|
--strategy)
37 strategy
=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;;
44 strategy_args
="${strategy_args}-s $strategy "
46 -h|
--h|
--he|
--hel|
--help)
50 # Pass thru anything that may be meant for fetch.
57 orig_head
=$
(git rev-parse
--verify HEAD
2>/dev
/null
)
58 git-fetch
--update-head-ok "$@" ||
exit 1
60 curr_head
=$
(git rev-parse
--verify HEAD
2>/dev
/null
)
61 if test "$curr_head" != "$orig_head"
63 # The fetch involved updating the current branch.
65 # The working tree and the index file is still based on the
66 # $orig_head commit, but we are merging into $curr_head.
67 # First update the working tree to match $curr_head.
69 echo >&2 "Warning: fetch updated the current branch head."
70 echo >&2 "Warning: fast forwarding your working tree from"
71 echo >&2 "Warning: commit $orig_head."
72 git update-index
--refresh 2>/dev
/null
73 git read-tree
-u -m "$orig_head" "$curr_head" ||
74 die
'Cannot fast-forward your working tree.
75 After making sure that you saved anything precious from
76 $ git diff '$orig_head'
83 merge_head
=$
(sed -e '/ not-for-merge /d' \
84 -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \
89 curr_branch
=$
(git symbolic-ref
-q HEAD
)
92 1) echo >&2 "You are not currently on a branch; you must explicitly"
93 echo >&2 "specify which branch you wish to merge:"
94 echo >&2 " git pull <remote> <branch>"
98 curr_branch
=${curr_branch#refs/heads/}
100 echo >&2 "You asked me to pull without telling me which branch you"
101 echo >&2 "want to merge with, and 'branch.${curr_branch}.merge' in"
102 echo >&2 "your configuration file does not tell me either. Please"
103 echo >&2 "name which branch you want to merge on the command line and"
104 echo >&2 "try again (e.g. 'git pull <repository> <refspec>')."
105 echo >&2 "See git-pull(1) for details on the refspec."
107 echo >&2 "If you often merge with the same branch, you may want to"
108 echo >&2 "configure the following variables in your configuration"
111 echo >&2 " branch.${curr_branch}.remote = <nickname>"
112 echo >&2 " branch.${curr_branch}.merge = <remote-ref>"
113 echo >&2 " remote.<nickname>.url = <url>"
114 echo >&2 " remote.<nickname>.fetch = <refspec>"
116 echo >&2 "See git-config(1) for details."
120 if test -z "$orig_head"
122 echo >&2 "Cannot merge multiple branches into empty head"
128 if test -z "$orig_head"
130 git update-ref
-m "initial pull" HEAD
$merge_head "" &&
131 git read-tree
--reset -u HEAD ||
exit 1
135 merge_name
=$
(git fmt-merge-msg
<"$GIT_DIR/FETCH_HEAD") ||
exit
136 exec git-merge
$no_summary $no_commit $squash $strategy_args \
137 "$merge_name" HEAD
$merge_head