Diff between two blobs should take mode changes into account now.
[gitweb.git] / builtin-branch.c
index 42b1ff129e7d5bbea47a4d1af955395014f200f9..7408285050a0f41a33d31c73e79c2fdefe567593 100644 (file)
@@ -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);
        }
@@ -482,6 +493,7 @@ static void rename_branch(const char *oldname, const char *newname, int force)
 {
        char oldref[PATH_MAX], newref[PATH_MAX], logmsg[PATH_MAX*2 + 100];
        unsigned char sha1[20];
+       char oldsection[PATH_MAX], newsection[PATH_MAX];
 
        if (!oldname)
                die("cannot rename the current branch while not on any.");
@@ -510,6 +522,11 @@ static void rename_branch(const char *oldname, const char *newname, int force)
        /* no need to pass logmsg here as HEAD didn't really move */
        if (!strcmp(oldname, head) && create_symref("HEAD", newref, NULL))
                die("Branch renamed to %s, but HEAD is not updated!", newname);
+
+       snprintf(oldsection, sizeof(oldsection), "branch.%s", oldref + 11);
+       snprintf(newsection, sizeof(newsection), "branch.%s", newref + 11);
+       if (git_config_rename_section(oldsection, newsection) < 0)
+               die("Branch is renamed, but update of config-file failed");
 }
 
 int cmd_branch(int argc, const char **argv, const char *prefix)