mirror of
https://github.com/git/git.git
synced 2024-06-13 11:56:20 +02:00
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>
This commit is contained in:
parent
3e03aaf523
commit
05dd8e2ee2
32
git-fetch.sh
32
git-fetch.sh
|
@ -54,6 +54,10 @@ append_fetch_head () {
|
||||||
remote_name_="$3"
|
remote_name_="$3"
|
||||||
remote_nick_="$4"
|
remote_nick_="$4"
|
||||||
local_name_="$5"
|
local_name_="$5"
|
||||||
|
case "$6" in
|
||||||
|
t) not_for_merge_='not-for-merge' ;;
|
||||||
|
'') not_for_merge_= ;;
|
||||||
|
esac
|
||||||
|
|
||||||
# remote-nick is the URL given on the command line (or a shorthand)
|
# remote-nick is the URL given on the command line (or a shorthand)
|
||||||
# remote-name is the $GIT_DIR relative refs/ path we computed
|
# remote-name is the $GIT_DIR relative refs/ path we computed
|
||||||
|
@ -78,10 +82,11 @@ append_fetch_head () {
|
||||||
if git-cat-file commit "$head_" >/dev/null 2>&1
|
if git-cat-file commit "$head_" >/dev/null 2>&1
|
||||||
then
|
then
|
||||||
headc_=$(git-rev-parse --verify "$head_^0") || exit
|
headc_=$(git-rev-parse --verify "$head_^0") || exit
|
||||||
echo "$headc_ $note_" >>$GIT_DIR/FETCH_HEAD
|
echo "$headc_ $not_for_merge_ $note_" >>$GIT_DIR/FETCH_HEAD
|
||||||
echo >&2 "* committish: $head_"
|
echo >&2 "* committish: $head_"
|
||||||
echo >&2 " $note_"
|
echo >&2 " $note_"
|
||||||
else
|
else
|
||||||
|
echo "$head_ not-for-merge $note_" >>$GIT_DIR/FETCH_HEAD
|
||||||
echo >&2 "* non-commit: $head_"
|
echo >&2 "* non-commit: $head_"
|
||||||
echo >&2 " $note_"
|
echo >&2 " $note_"
|
||||||
fi
|
fi
|
||||||
|
@ -157,6 +162,13 @@ do
|
||||||
|
|
||||||
# These are relative path from $GIT_DIR, typically starting at refs/
|
# These are relative path from $GIT_DIR, typically starting at refs/
|
||||||
# but may be HEAD
|
# but may be HEAD
|
||||||
|
if expr "$ref" : '\.' >/dev/null
|
||||||
|
then
|
||||||
|
not_for_merge=t
|
||||||
|
ref=$(expr "$ref" : '\.\(.*\)')
|
||||||
|
else
|
||||||
|
not_for_merge=
|
||||||
|
fi
|
||||||
if expr "$ref" : '\+' >/dev/null
|
if expr "$ref" : '\+' >/dev/null
|
||||||
then
|
then
|
||||||
single_force=t
|
single_force=t
|
||||||
|
@ -216,7 +228,8 @@ do
|
||||||
continue ;;
|
continue ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
append_fetch_head "$head" "$remote" "$remote_name" "$remote_nick" "$local_name"
|
append_fetch_head "$head" "$remote" \
|
||||||
|
"$remote_name" "$remote_nick" "$local_name" "$not_for_merge"
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -241,16 +254,27 @@ http://* | https://* | rsync://* )
|
||||||
case "$ref" in
|
case "$ref" in
|
||||||
+$remote_name:*)
|
+$remote_name:*)
|
||||||
single_force=t
|
single_force=t
|
||||||
|
not_for_merge=
|
||||||
|
found="$ref"
|
||||||
|
break ;;
|
||||||
|
.+$remote_name:*)
|
||||||
|
single_force=t
|
||||||
|
not_for_merge=t
|
||||||
|
found="$ref"
|
||||||
|
break ;;
|
||||||
|
.$remote_name:*)
|
||||||
|
not_for_merge=t
|
||||||
found="$ref"
|
found="$ref"
|
||||||
break ;;
|
break ;;
|
||||||
$remote_name:*)
|
$remote_name:*)
|
||||||
|
not_for_merge=
|
||||||
found="$ref"
|
found="$ref"
|
||||||
break ;;
|
break ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
local_name=$(expr "$found" : '[^:]*:\(.*\)')
|
local_name=$(expr "$found" : '[^:]*:\(.*\)')
|
||||||
append_fetch_head "$sha1" "$remote" "$remote_name" "$remote_nick" "$local_name"
|
append_fetch_head "$sha1" "$remote" \
|
||||||
|
"$remote_name" "$remote_nick" "$local_name" "$not_for_merge"
|
||||||
done || exit
|
done || exit
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -31,6 +31,8 @@ sub andjoin {
|
||||||
my ($bname, $tname, $gname, $src);
|
my ($bname, $tname, $gname, $src);
|
||||||
chomp;
|
chomp;
|
||||||
s/^[0-9a-f]* //;
|
s/^[0-9a-f]* //;
|
||||||
|
next if (/^not-for-merge/);
|
||||||
|
s/^ //;
|
||||||
if (s/ of (.*)$//) {
|
if (s/ of (.*)$//) {
|
||||||
$src = $1;
|
$src = $1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -86,7 +88,7 @@ sub andjoin {
|
||||||
$src{$src}{GENERIC});
|
$src{$src}{GENERIC});
|
||||||
my $this = join(', ', @this);
|
my $this = join(', ', @this);
|
||||||
if ($src ne '.') {
|
if ($src ne '.') {
|
||||||
$this .= " from $src";
|
$this .= " of $src";
|
||||||
}
|
}
|
||||||
push @msg, $this;
|
push @msg, $this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,8 +65,11 @@ get_remote_default_refs_for_push () {
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# Subroutine to canonicalize remote:local notation
|
# Subroutine to canonicalize remote:local notation.
|
||||||
canon_refs_list_for_fetch () {
|
canon_refs_list_for_fetch () {
|
||||||
|
# Leave only the first one alone; add prefix . to the rest
|
||||||
|
# to prevent the secondary branches to be merged by default.
|
||||||
|
dot_prefix=
|
||||||
for ref
|
for ref
|
||||||
do
|
do
|
||||||
force=
|
force=
|
||||||
|
@ -91,7 +94,8 @@ canon_refs_list_for_fetch () {
|
||||||
heads/* | tags/* ) local="refs/$local" ;;
|
heads/* | tags/* ) local="refs/$local" ;;
|
||||||
*) local="refs/heads/$local" ;;
|
*) local="refs/heads/$local" ;;
|
||||||
esac
|
esac
|
||||||
echo "${force}${remote}:${local}"
|
echo "${dot_prefix}${force}${remote}:${local}"
|
||||||
|
dot_prefix=.
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +111,9 @@ get_remote_default_refs_for_fetch () {
|
||||||
echo "refs/heads/${remote_branch}:refs/heads/$1"
|
echo "refs/heads/${remote_branch}:refs/heads/$1"
|
||||||
;;
|
;;
|
||||||
remotes)
|
remotes)
|
||||||
|
# This prefixes the second and later default refspecs
|
||||||
|
# with a '.', to signal git-fetch to mark them
|
||||||
|
# not-for-merge.
|
||||||
canon_refs_list_for_fetch $(sed -ne '/^Pull: */{
|
canon_refs_list_for_fetch $(sed -ne '/^Pull: */{
|
||||||
s///p
|
s///p
|
||||||
}' "$GIT_DIR/remotes/$1")
|
}' "$GIT_DIR/remotes/$1")
|
||||||
|
|
|
@ -24,7 +24,9 @@ then
|
||||||
die "You need to first update your working tree."
|
die "You need to first update your working tree."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
merge_head=$(sed -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | tr '\012' ' ')
|
merge_head=$(sed -e '/ not-for-merge /d' \
|
||||||
|
-e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \
|
||||||
|
tr '\012' ' ')
|
||||||
|
|
||||||
case "$merge_head" in
|
case "$merge_head" in
|
||||||
'')
|
'')
|
||||||
|
|
Loading…
Reference in New Issue