3 # Copyright (c) 2005 Junio C Hamano
5 # Fetch one or more remote refs and merge it/them into the current HEAD.
7 . git-sh-setup || die
"Not a git archive"
10 die
"git pull [-n] [-s strategy]... <repo> <head>..."
13 strategy_args
= no_summary
=
14 while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
17 -n|
--n|
--no|
--no-|
--no-s|
--no-su|
--no-sum|
--no-summ|\
18 --no-summa|
--no-summar|
--no-summary)
20 -s=*|
--s=*|
--st=*|
--str=*|
--stra=*|
--strat=*|
--strate=*|\
21 --strateg=*|
--strategy=*|\
22 -s|
--s|
--st|
--str|
--stra|
--strat|
--strate|
--strateg|
--strategy)
25 strategy
=`expr "$1" : '-[^=]*=\(.*\)'` ;;
32 strategy_args
="${strategy_args}-s $strategy "
41 orig_head
=$
(cat "$GIT_DIR/HEAD") || die
"Pulling into a black hole?"
42 git-fetch
--update-head-ok "$@" ||
exit 1
44 curr_head
=$
(cat "$GIT_DIR/HEAD")
45 if test "$curr_head" != "$orig_head"
47 # The fetch involved updating the current branch.
49 # The working tree and the index file is still based on the
50 # $orig_head commit, but we are merging into $curr_head.
51 # First update the working tree to match $curr_head.
53 echo >&2 "Warning: fetch updated the current branch head."
54 echo >&2 "Warning: fast forwarding your working tree."
55 git-read-tree
-u -m "$orig_head" "$curr_head" ||
56 die
"You need to first update your working tree."
59 merge_head
=$
(sed -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD |
tr '\012' ' ')
63 merge_name
="Octopus merge of "$
(
69 my ($label, $labels, $stuff, $src) = @_;
70 my $l = scalar @$stuff;
76 $m = "$label $stuff->[0]";
80 join (", ", @{$stuff}[0..$l-2]) .
90 my ($bname, $tname, $gname, $src);
97 if (! exists $src{$src}) {
99 $src{$src} = { BRANCH => [], TAG => [], GENERIC => [] };
101 if (/^branch (.*)$/) {
102 push @{$src{$src}{BRANCH}}, $1;
104 elsif (/^tag (.*)$/) {
105 push @{$src{$src}{TAG}}, $1;
108 push @{$src{$src}{GENERIC}}, $1;
113 my $bag = $src{$src}{BRANCH};
115 push @msg, andjoin("branch", "branches", $bag, $src);
117 $bag = $src{$src}{TAG};
119 push @msg, andjoin("tag", "tags", $bag, $src);
121 $bag = $src{$src}{GENERIC};
123 push @msg, andjoin("commit", "commits", $bag, $src);
126 print join("; ", @msg);
127 ' "$GIT_DIR"/FETCH_HEAD
131 merge_name
="Merge "$
(sed -e 's/^[0-9a-f]* //' \
132 "$GIT_DIR"/FETCH_HEAD
)
136 case "$merge_head" in
138 echo >&2 "No changes."
143 git-merge
$no_summary $strategy_args "$merge_name" HEAD
$merge_head