Merge branch 'jc/maint-apply-report-offset' into maint
[gitweb.git] / branch.c
index 40d3c4574350dffdfd65d06a002b537b1cc23302..93dc866f8c09a2da2308c4fd677178b043f2d4d5 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -49,9 +49,19 @@ static int should_setup_rebase(const char *origin)
 
 void install_branch_config(int flag, const char *local, const char *origin, const char *remote)
 {
+       const char *shortname = remote + 11;
+       int remote_is_branch = !prefixcmp(remote, "refs/heads/");
        struct strbuf key = STRBUF_INIT;
        int rebasing = should_setup_rebase(origin);
 
+       if (remote_is_branch
+           && !strcmp(local, shortname)
+           && !origin) {
+               warning("Not setting branch %s as its own upstream.",
+                       local);
+               return;
+       }
+
        strbuf_addf(&key, "branch.%s.remote", local);
        git_config_set(key.buf, origin ? origin : ".");
 
@@ -71,8 +81,8 @@ void install_branch_config(int flag, const char *local, const char *origin, cons
                strbuf_addstr(&key, origin ? "remote" : "local");
 
                /* Are we tracking a proper "branch"? */
-               if (!prefixcmp(remote, "refs/heads/")) {
-                       strbuf_addf(&key, " branch %s", remote + 11);
+               if (remote_is_branch) {
+                       strbuf_addf(&key, " branch %s", shortname);
                        if (origin)
                                strbuf_addf(&key, " from %s", origin);
                }
@@ -149,7 +159,7 @@ void create_branch(const char *head,
                        dont_change_ref = 1;
                else if (!force)
                        die("A branch named '%s' already exists.", name);
-               else if (!is_bare_repository() && !strcmp(head, name))
+               else if (!is_bare_repository() && head && !strcmp(head, name))
                        die("Cannot force update the current branch.");
                forcing = 1;
        }
@@ -188,7 +198,7 @@ void create_branch(const char *head,
                log_all_ref_updates = 1;
 
        if (forcing)
-               snprintf(msg, sizeof msg, "branch: Reset from %s",
+               snprintf(msg, sizeof msg, "branch: Reset to %s",
                         start_name);
        else if (!dont_change_ref)
                snprintf(msg, sizeof msg, "branch: Created from %s",