Allow checkout -B <current-branch> to update the current branch

When on master, "git checkout -B master <commit>" is a more natural way to
say "git reset --keep <commit>", which was originally invented for the
exact purpose of moving to the named commit while keeping the local changes
around.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jonathan Nieder
2011-11-26 02:54:55 -06:00
committed by Junio C Hamano
parent 3f59481e33
commit 39bd6f7261
5 changed files with 23 additions and 12 deletions

View File

@ -540,7 +540,9 @@ static void update_refs_for_switch(struct checkout_opts *opts,
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 @@ static void update_refs_for_switch(struct checkout_opts *opts,
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 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
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);
}