{"thread":{"id":"18120","subject":"[PATCHv2] Make git-clone respect branch.autosetuprebase","startedAt":"2009-03-03T20:15:07Z","lastAt":"2009-03-03T20:15:07Z","messageCount":1,"participants":["pknotz@sandia.gov"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"106926","messageId":"1236111307-32055-1-git-send-email-pknotz@sandia.gov","threadId":"18120","inReplyTo":null,"subject":"[PATCHv2] Make git-clone respect branch.autosetuprebase","fromName":"","fromEmail":"pknotz@sandia.gov","sentAt":"2009-03-03T20:15:07Z","receivedAt":"2009-03-03T20:15:07Z","isPatch":false,"sender":{"key":"patnotz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45364?v=4"},"body":"From: Pat Notz <pknotz@sandia.gov>\n\nWhen git-clone creates an initial branch it was not\nchecking the branch.autosetuprebase configuration\noption (which may exist in ~/.gitconfig).\n\nAdded function to branch.c to handle autorebase\nconfiguration setup.\n\nSigned-off-by: Pat Notz <pknotz@sandia.gov>\n---\n branch.c         |   23 ++++++++++++++++-------\n branch.h         |    9 +++++++++\n builtin-clone.c  |    3 +++\n t/t5601-clone.sh |   14 ++++++++++++++\n 4 files changed, 42 insertions(+), 7 deletions(-)\n\ndiff --git a/branch.c b/branch.c\nindex 1f00e44..ee8b69d 100644\n--- a/branch.c\n+++ b/branch.c\n@@ -32,21 +32,33 @@ static int find_tracked_branch(struct remote *remote, void *priv)\n \treturn 0;\n }\n \n-static int should_setup_rebase(const struct tracking *tracking)\n+static int should_setup_rebase(const char * remote)\n {\n \tswitch (autorebase) {\n \tcase AUTOREBASE_NEVER:\n \t\treturn 0;\n \tcase AUTOREBASE_LOCAL:\n-\t\treturn tracking->remote == NULL;\n+\t\treturn remote == NULL;\n \tcase AUTOREBASE_REMOTE:\n-\t\treturn tracking->remote != NULL;\n+\t\treturn remote != NULL;\n \tcase AUTOREBASE_ALWAYS:\n \t\treturn 1;\n \t}\n \treturn 0;\n }\n \n+int setup_autorebase(const char *local, const char *remote_tracked_branch)\n+{\n+\tif (should_setup_rebase(remote_tracked_branch)) {\n+\t\tstruct strbuf key = STRBUF_INIT;\n+\t\tstrbuf_addf(&key, \"branch.%s.rebase\", local);\n+\t\tgit_config_set(key.buf, \"true\");\n+\t\tstrbuf_release(&key);\n+\t\treturn 1;\n+\t}\n+\treturn 0;\n+}\n+\n /*\n  * This is called when new_ref is branched off of orig_ref, and tries\n  * to infer the settings for branch.<new_ref>.{remote,merge} from the\n@@ -86,11 +98,8 @@ static int setup_tracking(const char *new_ref, const char *orig_ref,\n \tgit_config_set(key, tracking.src ? tracking.src : orig_ref);\n \tprintf(\"Branch %s set up to track %s branch %s.\\n\", new_ref,\n \t\ttracking.remote ? \"remote\" : \"local\", orig_ref);\n-\tif (should_setup_rebase(&tracking)) {\n-\t\tsprintf(key, \"branch.%s.rebase\", new_ref);\n-\t\tgit_config_set(key, \"true\");\n+\tif (setup_autorebase(new_ref, tracking.remote))\n \t\tprintf(\"This branch will rebase on pull.\\n\");\n-\t}\n \tfree(tracking.src);\n \n \treturn 0;\ndiff --git a/branch.h b/branch.h\nindex 9f0c2a2..b332c09 100644\n--- a/branch.h\n+++ b/branch.h\n@@ -21,4 +21,13 @@ void create_branch(const char *head, const char *name, const char *start_name,\n  */\n void remove_branch_state(void);\n \n+/*\n+ * Used when creating a new branch to properly setup the autorebase flag\n+ * in the git-config file.  If the new branch (\"local\") is created from\n+ * a remote branch then remote_tracked_branch should be non-NULL.  If\n+ * the new branch is being created from another local branch then\n+ * remote_tracked_branch should be NULL.\n+ */\n+int setup_autorebase(const char *local, const char *remote_tracked_branch);\n+\n #endif\ndiff --git a/builtin-clone.c b/builtin-clone.c\nindex c338910..587c834 100644\n--- a/builtin-clone.c\n+++ b/builtin-clone.c\n@@ -17,6 +17,7 @@\n #include \"unpack-trees.h\"\n #include \"transport.h\"\n #include \"strbuf.h\"\n+#include \"branch.h\"\n #include \"dir.h\"\n #include \"pack-refs.h\"\n #include \"sigchain.h\"\n@@ -360,6 +361,8 @@ static void install_branch_config(const char *local,\n \tstrbuf_reset(&key);\n \tstrbuf_addf(&key, \"branch.%s.merge\", local);\n \tgit_config_set(key.buf, remote);\n+\tif (setup_autorebase(local, remote))\n+\t\tprintf(\"Default branch '%s' will rebase on pull.\\n\", local);\n \tstrbuf_release(&key);\n }\n \ndiff --git a/t/t5601-clone.sh b/t/t5601-clone.sh\nindex 44793f2..0f8b43c 100755\n--- a/t/t5601-clone.sh\n+++ b/t/t5601-clone.sh\n@@ -159,4 +159,18 @@ test_expect_success 'clone a void' '\n \ttest_cmp target-6/.git/config target-7/.git/config\n '\n \n+test_expect_success 'clone respects global branch.autosetuprebase' '\n+\tHOME=\"`pwd`\" &&\n+\texport HOME &&\n+\ttest_config=\"$HOME\"/.gitconfig &&\n+\tunset GIT_CONFIG_NOGLOBAL &&\n+\tgit config -f \"$test_config\" branch.autosetuprebase remote &&\n+\trm -fr dst &&\n+\tgit clone src dst &&\n+\tcd dst &&\n+\texpected=\"ztrue\" &&\n+\tactual=\"z$(git config branch.master.rebase)\" &&\n+\ttest $expected = $actual\n+'\n+\n test_done\n-- \n1.6.1.2\n"}]}