git-branch: Support local --track via a special remote `.'
PATCH 3/3 git-branch: Support local --track via a special remote `.'
From: Paolo Bonzini <[email protected]>
The patch adds --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 Santi Béjar <[email protected]>
---
This is an updated patch of:
[PATCH, fixed version] git-fetch, git-branch: Support local --track via a special
builtin-branch.c | 39 +++++++++++++++++++++++++-------------- git-checkout.sh | 2 +- t/t3200-branch.sh | 6 ++++++ t/t9109-git-svn-pull.sh | 31 +++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 15 deletions(-) create mode 100755 t/t9109-git-svn-pull.sh
builtin-branch.c +25 -14
@@ -372,9 +372,26 @@ static int get_remote_config(const char *key, const char *value)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 ]; +if (sizeof (key) <= +snprintf (key,sizeof (key),"branch.%s.remote" , name)) +die ("what a long branch name you have!" ); +git_config_set (key, config_remote); + +/* +* We do not have to check if we have enough space for +* the 'merge' key, since it's shorter than the +* previous 'remote' key, which we already checked. +*/ +snprintf (key,sizeof (key),"branch.%s.merge" , name); +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)
@@ -384,21 +401,15 @@ static void set_branch_defaults(const char *name, const char *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) { -if (sizeof (key) <= -snprintf (key,sizeof (key),"branch.%s.remote" , name)) -die ("what a long branch name you have!" ); -git_config_set (key, config_remote); - -/* -* We do not have to check if we have enough space for -* the 'merge' key, since it's shorter than the -* previous 'remote' key, which we already checked. -*/ -snprintf (key,sizeof (key),"branch.%s.merge" , name); -git_config_set (key, config_repo); - +set_branch_merge (name, config_remote, config_repo);printf ("Branch %s set up to track remote branch %s.\n" , name, real_ref); }
git-checkout.sh +1 -1
@@ -89,7 +89,7 @@ while [ "$#" != "0" ]; do esac done -case "$new_branch,$track" in +case "$newbranch,$track" in ,--*) die "git checkout: --track and --no-track require -b" esac
t/t3200-branch.sh +6 -0
@@ -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-show-ref -q refs/remotes/local/master || git-fetch local) && git-branch --no-track my2 local/master && + git-config branch.autosetupmerge false && ! test $(git-config branch.my2.remote) = local && ! 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 cat >expect <<EOF 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
t/t9109-git-svn-pull.sh new file +31 -0
@@ -0,0 +1,31 @@ +#!/bin/sh +# +# Copyright (c) 2007 Paolo Bonzini +# + +test_description='git-svn pull test' +. ./lib-git-svn.sh + +mkdir import + +cd import + echo Hello World > motd + svn import -m 'import for git-svn' . "$svnrepo" >/dev/null +cd .. + +test_expect_success 'initialize git-svn and fetch' " + git-svn init $svnrepo + git-svn fetch" + +svn co $svnrepo test_wc > /dev/null +cd test_wc + echo Goodbye World > motd + svn commit -m "another svn commit" > /dev/null +cd .. + +test_expect_success 'fetch and pull latest from svn' \ + 'git-svn fetch && + git pull . remotes/git-svn && + grep Goodbye motd' + +test_done
Signature · 6 lines
1.5.0.3.1021.g5897 -- Buscant signatura... Buscant signatura...fet