From: Junio C Hamano Date: Wed, 28 Dec 2011 19:32:33 +0000 (-0800) Subject: Merge branch 'jn/branch-move-to-self' into maint X-Git-Tag: v1.7.8.2~22 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/79587741cbed7704d2e7213c999cf2841af3000d?ds=inline;hp=-c Merge branch 'jn/branch-move-to-self' into maint * jn/branch-move-to-self: Allow checkout -B to update the current branch branch: allow a no-op "branch -M HEAD" --- 79587741cbed7704d2e7213c999cf2841af3000d diff --combined builtin/branch.c index 55cad766c7,823789fc95..df908ed8f5 --- a/builtin/branch.c +++ b/builtin/branch.c @@@ -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.")); @@@ -583,7 -584,13 +584,13 @@@ 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) @@@ -726,11 -733,11 +733,11 @@@ 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 51840b9784,ca00a8538a..44e73b5a4f --- a/builtin/checkout.c +++ b/builtin/checkout.c @@@ -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); } @@@ -565,8 -567,12 +567,12 @@@ 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); }