git-fetch, git-branch: Support local --track via a special remote '.'
This patch adds support for a dummy remote '.' to avoid having to declare a fake remote like [remote "local"] url = . fetch = refs/heads/*:refs/heads/* Such a builtin remote simplifies the operation of "git-fetch", which will populate FETCH_HEAD but will not pretend that two repositories are in use, will not create a thin pack, and will not perform any useless remapping of names. The speed improvement is around 20%, and it should improve more if "git-fetch" is converted to a builtin. To this end, git-parse-remote is grown with a new kind of remote, 'builtin'. In git-fetch.sh, we treat the builtin remote specially in that it needs no pack/store operations. In fact, doing git-fetch on a builtin remote will simply populate FETCH_HEAD appropriately. The patch also improves of the --track/--no-track support, extending it so that branch.<name>.remote items referring '.' can be created. Finally, it fixes a typo in git-checkout.sh. Signed-off-by: Paolo Bonzini <bonzini@gnu.org> Signed-off-by: Junio C Hamano <junkio@cox.net>maint
parent
803527f1d9
commit
9debc3241b
|
@ -272,6 +272,10 @@ branch.<name>.merge::
|
||||||
`git fetch`) to lookup the default branch for merging. Without
|
`git fetch`) to lookup the default branch for merging. Without
|
||||||
this option, `git pull` defaults to merge the first refspec fetched.
|
this option, `git pull` defaults to merge the first refspec fetched.
|
||||||
Specify multiple values to get an octopus merge.
|
Specify multiple values to get an octopus merge.
|
||||||
|
If you wish to setup `git pull` so that it merges into <name> from
|
||||||
|
another branch in the local repository, you can point
|
||||||
|
branch.<name>.merge to the desired branch, and use the special setting
|
||||||
|
`.` (a period) for branch.<name>.remote.
|
||||||
|
|
||||||
color.branch::
|
color.branch::
|
||||||
A boolean to enable/disable color in the output of
|
A boolean to enable/disable color in the output of
|
||||||
|
|
|
@ -372,20 +372,10 @@ static int get_remote_config(const char *key, const char *value)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_branch_defaults(const char *name, const char *real_ref)
|
static void set_branch_merge(const char *name, const char *config_remote,
|
||||||
|
const char *config_repo)
|
||||||
{
|
{
|
||||||
char key[1024];
|
char key[1024];
|
||||||
const char *slash = strrchr(real_ref, '/');
|
|
||||||
|
|
||||||
if (!slash)
|
|
||||||
return;
|
|
||||||
|
|
||||||
start_ref = real_ref;
|
|
||||||
start_len = strlen(real_ref);
|
|
||||||
base_len = slash - real_ref;
|
|
||||||
git_config(get_remote_config);
|
|
||||||
|
|
||||||
if (config_repo && config_remote) {
|
|
||||||
if (sizeof(key) <=
|
if (sizeof(key) <=
|
||||||
snprintf(key, sizeof(key), "branch.%s.remote", name))
|
snprintf(key, sizeof(key), "branch.%s.remote", name))
|
||||||
die("what a long branch name you have!");
|
die("what a long branch name you have!");
|
||||||
|
@ -398,7 +388,28 @@ static void set_branch_defaults(const char *name, const char *real_ref)
|
||||||
*/
|
*/
|
||||||
snprintf(key, sizeof(key), "branch.%s.merge", name);
|
snprintf(key, sizeof(key), "branch.%s.merge", name);
|
||||||
git_config_set(key, config_repo);
|
git_config_set(key, config_repo);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_branch_defaults(const char *name, const char *real_ref)
|
||||||
|
{
|
||||||
|
const char *slash = strrchr(real_ref, '/');
|
||||||
|
|
||||||
|
if (!slash)
|
||||||
|
return;
|
||||||
|
|
||||||
|
start_ref = real_ref;
|
||||||
|
start_len = strlen(real_ref);
|
||||||
|
base_len = slash - real_ref;
|
||||||
|
git_config(get_remote_config);
|
||||||
|
if (!config_repo && !config_remote &&
|
||||||
|
!prefixcmp(real_ref, "refs/heads/")) {
|
||||||
|
set_branch_merge(name, ".", real_ref);
|
||||||
|
printf("Branch %s set up to track local branch %s.\n",
|
||||||
|
name, real_ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config_repo && config_remote) {
|
||||||
|
set_branch_merge(name, config_remote, config_repo);
|
||||||
printf("Branch %s set up to track remote branch %s.\n",
|
printf("Branch %s set up to track remote branch %s.\n",
|
||||||
name, real_ref);
|
name, real_ref);
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ while [ "$#" != "0" ]; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
case "$new_branch,$track" in
|
case "$newbranch,$track" in
|
||||||
,--*)
|
,--*)
|
||||||
die "git checkout: --track and --no-track require -b"
|
die "git checkout: --track and --no-track require -b"
|
||||||
esac
|
esac
|
||||||
|
|
12
git-fetch.sh
12
git-fetch.sh
|
@ -157,7 +157,7 @@ then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fetch_native () {
|
fetch_all_at_once () {
|
||||||
|
|
||||||
eval=$(echo "$1" | git-fetch--tool parse-reflist "-")
|
eval=$(echo "$1" | git-fetch--tool parse-reflist "-")
|
||||||
eval "$eval"
|
eval "$eval"
|
||||||
|
@ -165,7 +165,9 @@ fetch_native () {
|
||||||
( : subshell because we muck with IFS
|
( : subshell because we muck with IFS
|
||||||
IFS=" $LF"
|
IFS=" $LF"
|
||||||
(
|
(
|
||||||
if test -f "$remote" ; then
|
if test "$remote" = . ; then
|
||||||
|
git-show-ref $rref || echo failed "$remote"
|
||||||
|
elif test -f "$remote" ; then
|
||||||
test -n "$shallow_depth" &&
|
test -n "$shallow_depth" &&
|
||||||
die "shallow clone with bundle is not supported"
|
die "shallow clone with bundle is not supported"
|
||||||
git-bundle unbundle "$remote" $rref ||
|
git-bundle unbundle "$remote" $rref ||
|
||||||
|
@ -188,7 +190,7 @@ fetch_native () {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch_dumb () {
|
fetch_per_ref () {
|
||||||
reflist="$1"
|
reflist="$1"
|
||||||
refs=
|
refs=
|
||||||
rref=
|
rref=
|
||||||
|
@ -292,10 +294,10 @@ fetch_dumb () {
|
||||||
fetch_main () {
|
fetch_main () {
|
||||||
case "$remote" in
|
case "$remote" in
|
||||||
http://* | https://* | ftp://* | rsync://* )
|
http://* | https://* | ftp://* | rsync://* )
|
||||||
fetch_dumb "$@"
|
fetch_per_ref "$@"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
fetch_native "$@"
|
fetch_all_at_once "$@"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,9 @@ get_data_source () {
|
||||||
*/*)
|
*/*)
|
||||||
echo ''
|
echo ''
|
||||||
;;
|
;;
|
||||||
|
.)
|
||||||
|
echo self
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
if test "$(git-config --get "remote.$1.url")"
|
if test "$(git-config --get "remote.$1.url")"
|
||||||
then
|
then
|
||||||
|
@ -31,6 +34,9 @@ get_remote_url () {
|
||||||
'')
|
'')
|
||||||
echo "$1"
|
echo "$1"
|
||||||
;;
|
;;
|
||||||
|
self)
|
||||||
|
echo "$1"
|
||||||
|
;;
|
||||||
config)
|
config)
|
||||||
git-config --get "remote.$1.url"
|
git-config --get "remote.$1.url"
|
||||||
;;
|
;;
|
||||||
|
@ -57,7 +63,7 @@ get_default_remote () {
|
||||||
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
|
||||||
'' | branches)
|
'' | branches | self)
|
||||||
;; # no default push mapping, just send matching refs.
|
;; # no default push mapping, just send matching refs.
|
||||||
config)
|
config)
|
||||||
git-config --get-all "remote.$1.push" ;;
|
git-config --get-all "remote.$1.push" ;;
|
||||||
|
@ -163,6 +169,10 @@ get_remote_default_refs_for_fetch () {
|
||||||
case "$data_source" in
|
case "$data_source" in
|
||||||
'')
|
'')
|
||||||
echo "HEAD:" ;;
|
echo "HEAD:" ;;
|
||||||
|
self)
|
||||||
|
canon_refs_list_for_fetch -d "$1" \
|
||||||
|
$(git-for-each-ref --format='%(refname):')
|
||||||
|
;;
|
||||||
config)
|
config)
|
||||||
canon_refs_list_for_fetch -d "$1" \
|
canon_refs_list_for_fetch -d "$1" \
|
||||||
$(git-config --get-all "remote.$1.fetch") ;;
|
$(git-config --get-all "remote.$1.fetch") ;;
|
||||||
|
@ -177,7 +187,7 @@ get_remote_default_refs_for_fetch () {
|
||||||
}' "$GIT_DIR/remotes/$1")
|
}' "$GIT_DIR/remotes/$1")
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
die "internal error: get-remote-default-ref-for-push $1" ;;
|
die "internal error: get-remote-default-ref-for-fetch $1" ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -145,9 +145,15 @@ test_expect_success 'test overriding tracking setup via --no-track' \
|
||||||
git-config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
|
git-config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
|
||||||
(git-show-ref -q refs/remotes/local/master || git-fetch local) &&
|
(git-show-ref -q refs/remotes/local/master || git-fetch local) &&
|
||||||
git-branch --no-track my2 local/master &&
|
git-branch --no-track my2 local/master &&
|
||||||
|
git-config branch.autosetupmerge false &&
|
||||||
! test $(git-config branch.my2.remote) = local &&
|
! test $(git-config branch.my2.remote) = local &&
|
||||||
! test $(git-config branch.my2.merge) = refs/heads/master'
|
! test $(git-config branch.my2.merge) = refs/heads/master'
|
||||||
|
|
||||||
|
test_expect_success 'test local tracking setup' \
|
||||||
|
'git branch --track my6 s &&
|
||||||
|
test $(git-config branch.my6.remote) = . &&
|
||||||
|
test $(git-config branch.my6.merge) = refs/heads/s'
|
||||||
|
|
||||||
# Keep this test last, as it changes the current branch
|
# Keep this test last, as it changes the current branch
|
||||||
cat >expect <<EOF
|
cat >expect <<EOF
|
||||||
0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
|
0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
|
||||||
|
|
|
@ -29,5 +29,29 @@ test_expect_success 'checking the results' '
|
||||||
diff file cloned/file
|
diff file cloned/file
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'test . as a remote' '
|
||||||
|
|
||||||
|
git branch copy master &&
|
||||||
|
git config branch.copy.remote . &&
|
||||||
|
git config branch.copy.merge refs/heads/master &&
|
||||||
|
echo updated >file &&
|
||||||
|
git commit -a -m updated &&
|
||||||
|
git checkout copy &&
|
||||||
|
test `cat file` = file &&
|
||||||
|
git pull &&
|
||||||
|
test `cat file` = updated
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'the default remote . should not break explicit pull' '
|
||||||
|
git checkout -b second master^ &&
|
||||||
|
echo modified >file &&
|
||||||
|
git commit -a -m modified &&
|
||||||
|
git checkout copy &&
|
||||||
|
git reset --hard HEAD^ &&
|
||||||
|
test `cat file` = file &&
|
||||||
|
git pull . second &&
|
||||||
|
test `cat file` = modified
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue