Merge branch 'jn/branch-move-to-self' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 28 Dec 2011 19:32:33 +0000 (11:32 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 28 Dec 2011 19:32:33 +0000 (11:32 -0800)
* jn/branch-move-to-self:
Allow checkout -B <current-branch> to update the current branch
branch: allow a no-op "branch -M <current-branch> HEAD"

1  2 
builtin/branch.c
builtin/checkout.c
diff --combined builtin/branch.c
index 55cad766c7e3d284b1361b1beca8c5d51de96083,823789fc95f609ca5a763be545f3963c2fa5a1ec..df908ed8f55838702299c9a687a98502f91cf5da
@@@ -568,6 -568,7 +568,7 @@@ static void rename_branch(const char *o
        unsigned char sha1[20];
        struct strbuf oldsection = STRBUF_INIT, newsection = STRBUF_INIT;
        int recovery = 0;
+       int clobber_head_ok;
  
        if (!oldname)
                die(_("cannot rename the current branch while not on any."));
                        die(_("Invalid branch name: '%s'"), oldname);
        }
  
-       validate_new_branchname(newname, &newref, force, 0);
+       /*
+        * A command like "git branch -M currentbranch currentbranch" cannot
+        * cause the worktree to become inconsistent with HEAD, so allow it.
+        */
+       clobber_head_ok = !strcmp(oldname, newname);
+       validate_new_branchname(newname, &newref, force, clobber_head_ok);
  
        strbuf_addf(&logmsg, "Branch: renamed %s to %s",
                 oldref.buf, newref.buf);
@@@ -705,7 -712,7 +712,7 @@@ int cmd_branch(int argc, const char **a
        argc = parse_options(argc, argv, prefix, options, builtin_branch_usage,
                             0);
  
 -      if (!delete && !rename && !force_create && argc == 0)
 +      if (!delete && !rename && argc == 0)
                list = 1;
  
        if (!!delete + !!rename + !!force_create + !!list > 1)
                        rename_branch(argv[0], argv[1], rename > 1);
                else
                        usage_with_options(builtin_branch_usage, options);
 -      } else if (argc <= 2) {
 +      } else if (argc > 0 && argc <= 2) {
                if (kinds != REF_LOCAL_BRANCH)
                        die(_("-a and -r options to 'git branch' do not make sense with a branch name"));
                create_branch(head, argv[0], (argc == 2) ? argv[1] : head,
-                             force_create, reflog, track);
+                             force_create, reflog, 0, track);
        } else
                usage_with_options(builtin_branch_usage, options);
  
diff --combined builtin/checkout.c
index 51840b9784f0daec21087ec101304eaa6cbf73cd,ca00a8538ae2e49458046a41aa48f3285a9b6de9..44e73b5a4fc57f206c09b4c630d2028bf7475a51
@@@ -411,7 -411,7 +411,7 @@@ static int merge_working_tree(struct ch
                topts.fn = twoway_merge;
                topts.dir = xcalloc(1, sizeof(*topts.dir));
                topts.dir->flags |= DIR_SHOW_IGNORED;
 -              topts.dir->exclude_per_dir = ".gitignore";
 +              setup_standard_excludes(topts.dir);
                tree = parse_tree_indirect(old->commit ?
                                           old->commit->object.sha1 :
                                           EMPTY_TREE_SHA1_BIN);
@@@ -540,7 -540,9 +540,9 @@@ static void update_refs_for_switch(stru
                else
                        create_branch(old->name, opts->new_branch, new->name,
                                      opts->new_branch_force ? 1 : 0,
-                                     opts->new_branch_log, opts->track);
+                                     opts->new_branch_log,
+                                     opts->new_branch_force ? 1 : 0,
+                                     opts->track);
                new->name = opts->new_branch;
                setup_branch_path(new);
        }
                create_symref("HEAD", new->path, msg.buf);
                if (!opts->quiet) {
                        if (old->path && !strcmp(new->path, old->path)) {
-                               fprintf(stderr, _("Already on '%s'\n"),
-                                       new->name);
+                               if (opts->new_branch_force)
+                                       fprintf(stderr, _("Reset branch '%s'\n"),
+                                               new->name);
+                               else
+                                       fprintf(stderr, _("Already on '%s'\n"),
+                                               new->name);
                        } else if (opts->new_branch) {
                                if (opts->branch_exists)
                                        fprintf(stderr, _("Switched to and reset branch '%s'\n"), new->name);
@@@ -1057,7 -1063,8 +1063,8 @@@ int cmd_checkout(int argc, const char *
                struct strbuf buf = STRBUF_INIT;
  
                opts.branch_exists = validate_new_branchname(opts.new_branch, &buf,
-                                                            !!opts.new_branch_force, 0);
+                                                            !!opts.new_branch_force,
+                                                            !!opts.new_branch_force);
  
                strbuf_release(&buf);
        }