зеркало из https://github.com/microsoft/git.git
Merge branch 'sb/branch-attributes'
* sb/branch-attributes: Add test for the default merges in fetch. fetch: get the remote branches to merge from the branch properties Add t5510 to test per branch configuration affecting git-fetch. Fetch: default remote repository from branch properties
This commit is contained in:
Коммит
700899b624
|
@ -119,6 +119,13 @@ apply.whitespace::
|
||||||
Tells `git-apply` how to handle whitespaces, in the same way
|
Tells `git-apply` how to handle whitespaces, in the same way
|
||||||
as the '--whitespace' option. See gitlink:git-apply[1].
|
as the '--whitespace' option. See gitlink:git-apply[1].
|
||||||
|
|
||||||
|
branch.<name>.remote::
|
||||||
|
When in branch <name>, it tells `git fetch` which remote to fetch.
|
||||||
|
|
||||||
|
branch.<name>.merge::
|
||||||
|
When in branch <name>, it tells `git fetch` the default remote branch
|
||||||
|
to be merged.
|
||||||
|
|
||||||
pager.color::
|
pager.color::
|
||||||
A boolean to enable/disable colored output when the pager is in
|
A boolean to enable/disable colored output when the pager is in
|
||||||
use (default is true).
|
use (default is true).
|
||||||
|
|
|
@ -68,11 +68,10 @@ done
|
||||||
|
|
||||||
case "$#" in
|
case "$#" in
|
||||||
0)
|
0)
|
||||||
test -f "$GIT_DIR/branches/origin" ||
|
origin=$(get_default_remote)
|
||||||
test -f "$GIT_DIR/remotes/origin" ||
|
test -n "$(get_remote_url ${origin})" ||
|
||||||
git-repo-config --get remote.origin.url >/dev/null ||
|
die "Where do you want to fetch from today?"
|
||||||
die "Where do you want to fetch from today?"
|
set x $origin ; shift ;;
|
||||||
set origin ;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
remote_nick="$1"
|
remote_nick="$1"
|
||||||
|
|
|
@ -68,6 +68,12 @@ get_remote_url () {
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_default_remote () {
|
||||||
|
curr_branch=$(git-symbolic-ref HEAD | sed -e 's|^refs/heads/||')
|
||||||
|
origin=$(git-repo-config --get "branch.$curr_branch.remote")
|
||||||
|
echo ${origin:-origin}
|
||||||
|
}
|
||||||
|
|
||||||
get_remote_default_refs_for_push () {
|
get_remote_default_refs_for_push () {
|
||||||
data_source=$(get_data_source "$1")
|
data_source=$(get_data_source "$1")
|
||||||
case "$data_source" in
|
case "$data_source" in
|
||||||
|
@ -86,9 +92,22 @@ get_remote_default_refs_for_push () {
|
||||||
|
|
||||||
# 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
|
# If called from get_remote_default_refs_for_fetch
|
||||||
|
# leave the branches in branch.${curr_branch}.merge alone,
|
||||||
|
# or the first one otherwise; add prefix . to the rest
|
||||||
# to prevent the secondary branches to be merged by default.
|
# to prevent the secondary branches to be merged by default.
|
||||||
dot_prefix=
|
merge_branches=
|
||||||
|
if test "$1" = "-d"
|
||||||
|
then
|
||||||
|
shift ; remote="$1" ; shift
|
||||||
|
if test "$remote" = "$(get_default_remote)"
|
||||||
|
then
|
||||||
|
curr_branch=$(git-symbolic-ref HEAD | \
|
||||||
|
sed -e 's|^refs/heads/||')
|
||||||
|
merge_branches=$(git-repo-config \
|
||||||
|
--get-all "branch.${curr_branch}.merge")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
for ref
|
for ref
|
||||||
do
|
do
|
||||||
force=
|
force=
|
||||||
|
@ -101,6 +120,18 @@ canon_refs_list_for_fetch () {
|
||||||
expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
|
expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
|
||||||
remote=$(expr "z$ref" : 'z\([^:]*\):')
|
remote=$(expr "z$ref" : 'z\([^:]*\):')
|
||||||
local=$(expr "z$ref" : 'z[^:]*:\(.*\)')
|
local=$(expr "z$ref" : 'z[^:]*:\(.*\)')
|
||||||
|
dot_prefix=.
|
||||||
|
if test -z "$merge_branches"
|
||||||
|
then
|
||||||
|
merge_branches=$remote
|
||||||
|
dot_prefix=
|
||||||
|
else
|
||||||
|
for merge_branch in $merge_branches
|
||||||
|
do
|
||||||
|
[ "$remote" = "$merge_branch" ] &&
|
||||||
|
dot_prefix= && break
|
||||||
|
done
|
||||||
|
fi
|
||||||
case "$remote" in
|
case "$remote" in
|
||||||
'') remote=HEAD ;;
|
'') remote=HEAD ;;
|
||||||
refs/heads/* | refs/tags/* | refs/remotes/*) ;;
|
refs/heads/* | refs/tags/* | refs/remotes/*) ;;
|
||||||
|
@ -120,7 +151,6 @@ canon_refs_list_for_fetch () {
|
||||||
die "* refusing to create funny ref '$local_ref_name' locally"
|
die "* refusing to create funny ref '$local_ref_name' locally"
|
||||||
fi
|
fi
|
||||||
echo "${dot_prefix}${force}${remote}:${local}"
|
echo "${dot_prefix}${force}${remote}:${local}"
|
||||||
dot_prefix=.
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +161,7 @@ get_remote_default_refs_for_fetch () {
|
||||||
'' | config-partial | branches-partial)
|
'' | config-partial | branches-partial)
|
||||||
echo "HEAD:" ;;
|
echo "HEAD:" ;;
|
||||||
config)
|
config)
|
||||||
canon_refs_list_for_fetch \
|
canon_refs_list_for_fetch -d "$1" \
|
||||||
$(git-repo-config --get-all "remote.$1.fetch") ;;
|
$(git-repo-config --get-all "remote.$1.fetch") ;;
|
||||||
branches)
|
branches)
|
||||||
remote_branch=$(sed -ne '/#/s/.*#//p' "$GIT_DIR/branches/$1")
|
remote_branch=$(sed -ne '/#/s/.*#//p' "$GIT_DIR/branches/$1")
|
||||||
|
@ -139,10 +169,7 @@ 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
|
canon_refs_list_for_fetch -d "$1" $(sed -ne '/^Pull: */{
|
||||||
# with a '.', to signal git-fetch to mark them
|
|
||||||
# not-for-merge.
|
|
||||||
canon_refs_list_for_fetch $(sed -ne '/^Pull: */{
|
|
||||||
s///p
|
s///p
|
||||||
}' "$GIT_DIR/remotes/$1")
|
}' "$GIT_DIR/remotes/$1")
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Copyright (c) 2006, Junio C Hamano.
|
||||||
|
|
||||||
|
test_description='Per branch config variables affects "git fetch".
|
||||||
|
|
||||||
|
'
|
||||||
|
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
D=`pwd`
|
||||||
|
|
||||||
|
test_expect_success setup '
|
||||||
|
echo >file original &&
|
||||||
|
git add file &&
|
||||||
|
git commit -a -m original'
|
||||||
|
|
||||||
|
test_expect_success "clone and setup child repos" '
|
||||||
|
git clone . one &&
|
||||||
|
cd one &&
|
||||||
|
echo >file updated by one &&
|
||||||
|
git commit -a -m "updated by one" &&
|
||||||
|
cd .. &&
|
||||||
|
git clone . two &&
|
||||||
|
cd two &&
|
||||||
|
git repo-config branch.master.remote one &&
|
||||||
|
{
|
||||||
|
echo "URL: ../one/.git/"
|
||||||
|
echo "Pull: refs/heads/master:refs/heads/one"
|
||||||
|
} >.git/remotes/one
|
||||||
|
cd .. &&
|
||||||
|
git clone . three &&
|
||||||
|
cd three &&
|
||||||
|
git repo-config branch.master.remote two &&
|
||||||
|
git repo-config branch.master.merge refs/heads/one &&
|
||||||
|
{
|
||||||
|
echo "URL: ../two/.git/"
|
||||||
|
echo "Pull: refs/heads/master:refs/heads/two"
|
||||||
|
echo "Pull: refs/heads/one:refs/heads/one"
|
||||||
|
} >.git/remotes/two
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success "fetch test" '
|
||||||
|
cd "$D" &&
|
||||||
|
echo >file updated by origin &&
|
||||||
|
git commit -a -m "updated by origin" &&
|
||||||
|
cd two &&
|
||||||
|
git fetch &&
|
||||||
|
test -f .git/refs/heads/one &&
|
||||||
|
mine=`git rev-parse refs/heads/one` &&
|
||||||
|
his=`cd ../one && git rev-parse refs/heads/master` &&
|
||||||
|
test "z$mine" = "z$his"
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success "fetch test for-merge" '
|
||||||
|
cd "$D" &&
|
||||||
|
cd three &&
|
||||||
|
git fetch &&
|
||||||
|
test -f .git/refs/heads/two &&
|
||||||
|
test -f .git/refs/heads/one &&
|
||||||
|
master_in_two=`cd ../two && git rev-parse master` &&
|
||||||
|
one_in_two=`cd ../two && git rev-parse one` &&
|
||||||
|
{
|
||||||
|
echo "$master_in_two not-for-merge"
|
||||||
|
echo "$one_in_two "
|
||||||
|
} >expected &&
|
||||||
|
cut -f -2 .git/FETCH_HEAD >actual &&
|
||||||
|
diff expected actual'
|
||||||
|
|
||||||
|
test_done
|
Загрузка…
Ссылка в новой задаче