Fix default pull not to do an unintended Octopus.
The refspecs specified in the .git/remotes/<remote> on the "Pull: " lines are for fetching multiple heads in one go, but most of the time making an Octopus out of them is not what is wanted. Make git-fetch leave the marker in .git/FETCH_HEAD file so that later stages can tell which heads are for merging and which are not. Tom Prince made me realize how stupid the original behaviour was. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Sep 25, 2005 at 22:54 UTC
05dd8e2ee2ecba1b4ef1dbbde5c81281152604b4
4 files changed
+43
-8
git-fetch.sh
+28
-4
@@ -54,6 +54,10 @@ append_fetch_head () {
54
remote_name_="$3"
55
remote_nick_="$4"
56
local_name_="$5"
57
+ case "$6" in
58
+ t) not_for_merge_='not-for-merge' ;;
59
+ '') not_for_merge_= ;;
60
+ esac
61
62
# remote-nick is the URL given on the command line (or a shorthand)
63
# remote-name is the $GIT_DIR relative refs/ path we computed
@@ -78,10 +82,11 @@ append_fetch_head () {
82
if git-cat-file commit "$head_" >/dev/null 2>&1
83
then
84
headc_=$(git-rev-parse --verify "$head_^0") || exit
81
- echo "$headc_ $note_" >>$GIT_DIR/FETCH_HEAD
85
+ echo "$headc_ $not_for_merge_ $note_" >>$GIT_DIR/FETCH_HEAD
86
echo >&2 "* committish: $head_"
87
echo >&2 " $note_"
88
else
89
+ echo "$head_ not-for-merge $note_" >>$GIT_DIR/FETCH_HEAD
90
echo >&2 "* non-commit: $head_"
91
echo >&2 " $note_"
92
fi
@@ -157,6 +162,13 @@ do
162
163
# These are relative path from $GIT_DIR, typically starting at refs/
164
# but may be HEAD
165
+ if expr "$ref" : '\.' >/dev/null
166
+ then
167
+ not_for_merge=t
168
+ ref=$(expr "$ref" : '\.\(.*\)')
169
+ else
170
+ not_for_merge=
171
+ fi
172
if expr "$ref" : '\+' >/dev/null
173
then
174
single_force=t
@@ -216,7 +228,8 @@ do
228
continue ;;
229
esac
230
219
- append_fetch_head "$head" "$remote" "$remote_name" "$remote_nick" "$local_name"
231
+ append_fetch_head "$head" "$remote" \
232
+ "$remote_name" "$remote_nick" "$local_name" "$not_for_merge"
233
234
done
235
@@ -241,16 +254,27 @@ http://* | https://* | rsync://* )
254
case "$ref" in
255
+$remote_name:*)
256
single_force=t
257
+ not_for_merge=
258
+ found="$ref"
259
+ break ;;
260
+ .+$remote_name:*)
261
+ single_force=t
262
+ not_for_merge=t
263
+ found="$ref"
264
+ break ;;
265
+ .$remote_name:*)
266
+ not_for_merge=t
267
found="$ref"
268
break ;;
269
$remote_name:*)
270
+ not_for_merge=
271
found="$ref"
272
break ;;
273
esac
274
done
251
-
275
local_name=$(expr "$found" : '[^:]*:\(.*\)')
253
- append_fetch_head "$sha1" "$remote" "$remote_name" "$remote_nick" "$local_name"
276
+ append_fetch_head "$sha1" "$remote" \
277
+ "$remote_name" "$remote_nick" "$local_name" "$not_for_merge"
278
done || exit
279
;;
280
esac
git-fmt-merge-msg.perl
+3
-1
@@ -31,6 +31,8 @@ while (<>) {
31
my ($bname, $tname, $gname, $src);
32
chomp;
33
s/^[0-9a-f]* //;
34
+ next if (/^not-for-merge/);
35
+ s/^ //;
36
if (s/ of (.*)$//) {
37
$src = $1;
38
} else {
@@ -86,7 +88,7 @@ for my $src (@src) {
88
$src{$src}{GENERIC});
89
my $this = join(', ', @this);
90
if ($src ne '.') {
89
- $this .= " from $src";
91
+ $this .= " of $src";
92
}
93
push @msg, $this;
94
}
git-parse-remote.sh
+9
-2
@@ -65,8 +65,11 @@ get_remote_default_refs_for_push () {
65
esac
66
}
67
68
-# Subroutine to canonicalize remote:local notation
68
+# Subroutine to canonicalize remote:local notation.
69
canon_refs_list_for_fetch () {
70
+ # Leave only the first one alone; add prefix . to the rest
71
+ # to prevent the secondary branches to be merged by default.
72
+ dot_prefix=
73
for ref
74
do
75
force=
@@ -91,7 +94,8 @@ canon_refs_list_for_fetch () {
94
heads/* | tags/* ) local="refs/$local" ;;
95
*) local="refs/heads/$local" ;;
96
esac
94
- echo "${force}${remote}:${local}"
97
+ echo "${dot_prefix}${force}${remote}:${local}"
98
+ dot_prefix=.
99
done
100
}
101
@@ -107,6 +111,9 @@ get_remote_default_refs_for_fetch () {
111
echo "refs/heads/${remote_branch}:refs/heads/$1"
112
;;
113
remotes)
114
+ # This prefixes the second and later default refspecs
115
+ # with a '.', to signal git-fetch to mark them
116
+ # not-for-merge.
117
canon_refs_list_for_fetch $(sed -ne '/^Pull: */{
118
s///p
119
}' "$GIT_DIR/remotes/$1")
git-pull.sh
+3
-1
@@ -24,7 +24,9 @@ then
24
die "You need to first update your working tree."
25
fi
26
27
-merge_head=$(sed -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | tr '\012' ' ')
27
+merge_head=$(sed -e '/ not-for-merge /d' \
28
+ -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \
29
+ tr '\012' ' ')
30
31
case "$merge_head" in
32
'')