{"thread":{"id":"7234","subject":"[PATCH 3/3] git-branch: Support local --track via a special remote `.'","startedAt":"2007-03-13T16:30:55Z","lastAt":"2007-03-13T16:30:55Z","messageCount":1,"participants":["Santi Béjar"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"37011","messageId":"877itlf6m8.fsf@gmail.com","threadId":"7234","inReplyTo":null,"subject":"[PATCH 3/3] git-branch: Support local --track via a special remote `.'","fromName":"Santi Béjar","fromEmail":"sbejar@gmail.com","sentAt":"2007-03-13T16:30:55Z","receivedAt":"2007-03-13T16:30:55Z","isPatch":true,"sender":{"key":"santi@agolina.net","avatar":null},"body":"\nFrom: Paolo Bonzini  <bonzini@gnu.org>\n\nThe patch adds --track/--no-track support, extending\nit so that branch.<name>.remote items referring `.' can be created.\nFinally, it fixes a typo in git-checkout.sh.\n\nSigned-off-by: Santi Béjar <sbejar@gmail.com>\n---\n This is an updated patch of:\n\n [PATCH, fixed version] git-fetch, git-branch: Support local --track via\n a special\n\n builtin-branch.c        |   39 +++++++++++++++++++++++++--------------\n git-checkout.sh         |    2 +-\n t/t3200-branch.sh       |    6 ++++++\n t/t9109-git-svn-pull.sh |   31 +++++++++++++++++++++++++++++++\n 4 files changed, 63 insertions(+), 15 deletions(-)\n create mode 100755 t/t9109-git-svn-pull.sh\n\ndiff --git a/builtin-branch.c b/builtin-branch.c\nindex 42b1ff1..14c4219 100644\n--- a/builtin-branch.c\n+++ b/builtin-branch.c\n@@ -372,9 +372,26 @@ static int get_remote_config(const char *key, const char *value)\n \treturn 0;\n }\n \n-static void set_branch_defaults(const char *name, const char *real_ref)\n+static void set_branch_merge (const char *name, const char *config_remote,\n+\t\t\t      const char *config_repo)\n {\n \tchar key[1024];\n+\tif (sizeof(key) <=\n+\t    snprintf(key, sizeof(key), \"branch.%s.remote\", name))\n+\t\tdie(\"what a long branch name you have!\");\n+\tgit_config_set(key, config_remote);\n+\n+\t/*\n+\t * We do not have to check if we have enough space for\n+\t * the 'merge' key, since it's shorter than the\n+\t * previous 'remote' key, which we already checked.\n+\t */\n+\tsnprintf(key, sizeof(key), \"branch.%s.merge\", name);\n+\tgit_config_set(key, config_repo);\n+}\n+\n+static void set_branch_defaults(const char *name, const char *real_ref)\n+{\n \tconst char *slash = strrchr(real_ref, '/');\n \n \tif (!slash)\n@@ -384,21 +401,15 @@ static void set_branch_defaults(const char *name, const char *real_ref)\n \tstart_len = strlen(real_ref);\n \tbase_len = slash - real_ref;\n \tgit_config(get_remote_config);\n+\tif (!config_repo && !config_remote &&\n+\t    !prefixcmp (real_ref, \"refs/heads/\")) {\n+\t\tset_branch_merge (name, \".\", real_ref);\n+\t\tprintf(\"Branch %s set up to track local branch %s.\\n\",\n+\t\t       name, real_ref);\n+\t}\n \n \tif (config_repo && config_remote) {\n-\t\tif (sizeof(key) <=\n-\t\t    snprintf(key, sizeof(key), \"branch.%s.remote\", name))\n-\t\t\tdie(\"what a long branch name you have!\");\n-\t\tgit_config_set(key, config_remote);\n-\n-\t\t/*\n-\t\t * We do not have to check if we have enough space for\n-\t\t * the 'merge' key, since it's shorter than the\n-\t\t * previous 'remote' key, which we already checked.\n-\t\t */\n-\t\tsnprintf(key, sizeof(key), \"branch.%s.merge\", name);\n-\t\tgit_config_set(key, config_repo);\n-\n+\t\tset_branch_merge (name, config_remote, config_repo);\n \t\tprintf(\"Branch %s set up to track remote branch %s.\\n\",\n \t\t       name, real_ref);\n \t}\ndiff --git a/git-checkout.sh b/git-checkout.sh\nindex 6caa9fd..b292ff0 100755\n--- a/git-checkout.sh\n+++ b/git-checkout.sh\n@@ -89,7 +89,7 @@ while [ \"$#\" != \"0\" ]; do\n     esac\n done\n \n-case \"$new_branch,$track\" in\n+case \"$newbranch,$track\" in\n ,--*)\n \tdie \"git checkout: --track and --no-track require -b\"\n esac\ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex 75c000a..9558bdb 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -145,9 +145,15 @@ test_expect_success 'test overriding tracking setup via --no-track' \\\n      git-config remote.local.fetch refs/heads/*:refs/remotes/local/* &&\n      (git-show-ref -q refs/remotes/local/master || git-fetch local) &&\n      git-branch --no-track my2 local/master &&\n+     git-config branch.autosetupmerge false &&\n      ! test $(git-config branch.my2.remote) = local &&\n      ! test $(git-config branch.my2.merge) = refs/heads/master'\n \n+test_expect_success 'test local tracking setup' \\\n+    'git branch --track my6 s &&\n+     test $(git-config branch.my6.remote) = . &&\n+     test $(git-config branch.my6.merge) = refs/heads/s'\n+\n # Keep this test last, as it changes the current branch\n cat >expect <<EOF\n 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000\tbranch: Created from master\ndiff --git a/t/t9109-git-svn-pull.sh b/t/t9109-git-svn-pull.sh\nnew file mode 100755\nindex 0000000..58fa7df\n--- /dev/null\n+++ b/t/t9109-git-svn-pull.sh\n@@ -0,0 +1,31 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2007 Paolo Bonzini\n+#\n+\n+test_description='git-svn pull test'\n+. ./lib-git-svn.sh\n+\n+mkdir import\n+\n+cd import\n+\techo Hello World > motd\n+\tsvn import -m 'import for git-svn' . \"$svnrepo\" >/dev/null\n+cd ..\n+\n+test_expect_success 'initialize git-svn and fetch' \"\n+\tgit-svn init $svnrepo\n+\tgit-svn fetch\"\n+\n+svn co $svnrepo test_wc > /dev/null\n+cd test_wc\n+\techo Goodbye World > motd\n+\tsvn commit -m \"another svn commit\" > /dev/null\n+cd ..\n+\n+test_expect_success 'fetch and pull latest from svn' \\\n+\t'git-svn fetch &&\n+\t git pull . remotes/git-svn &&\n+\t grep Goodbye motd'\n+\n+test_done\n-- \n1.5.0.3.1021.g5897\n\n\n-- \nBuscant signatura...\nBuscant signatura...fet\n"}]}