summaryrefslogtreecommitdiff
path: root/builtin/checkout.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2019-03-29 10:39:10 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-04-02 04:57:00 (GMT)
commite342c63a4e070bd1398b9aa86ac4ce917edbadc7 (patch)
tree851c933ff4b53f79f4ff9f56e9f07536f9f23ee2 /builtin/checkout.c
parent5c06e26903fd69cf7a71bf2cf8281a84868525b0 (diff)
downloadgit-e342c63a4e070bd1398b9aa86ac4ce917edbadc7.zip
git-e342c63a4e070bd1398b9aa86ac4ce917edbadc7.tar.gz
git-e342c63a4e070bd1398b9aa86ac4ce917edbadc7.tar.bz2
switch: reject "do nothing" case
"git checkout" can be executed without any arguments. What it does is not exactly great: it switches from HEAD to HEAD and shows worktree modification as a side effect. Make switch reject this case. Just use "git status" if you want that side effect. For switch, you have to either - really switch a branch - (explicitly) detach from the current branch - create a new branch Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/checkout.c')
-rw-r--r--builtin/checkout.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 0584dc4..e9dfe38 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -55,6 +55,7 @@ struct checkout_opts {
int no_dwim_new_local_branch;
int discard_changes;
int accept_pathspec;
+ int switch_branch_doing_nothing_is_ok;
/*
* If new checkout options are added, skip_merge_working_tree
@@ -1338,6 +1339,12 @@ static int checkout_branch(struct checkout_opts *opts,
die(_("Cannot switch branch to a non-commit '%s'"),
new_branch_info->name);
+ if (!opts->switch_branch_doing_nothing_is_ok &&
+ !new_branch_info->name &&
+ !opts->new_branch &&
+ !opts->force_detach)
+ die(_("missing branch or commit argument"));
+
if (new_branch_info->path && !opts->force_detach && !opts->new_branch &&
!opts->ignore_other_worktrees) {
int flag;
@@ -1593,6 +1600,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
memset(&opts, 0, sizeof(opts));
opts.no_dwim_new_local_branch = 0;
+ opts.switch_branch_doing_nothing_is_ok = 1;
opts.accept_pathspec = 1;
options = parse_options_dup(checkout_options);
@@ -1624,6 +1632,7 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
memset(&opts, 0, sizeof(opts));
opts.no_dwim_new_local_branch = 0;
opts.accept_pathspec = 0;
+ opts.switch_branch_doing_nothing_is_ok = 0;
options = parse_options_dup(switch_options);
options = add_common_options(&opts, options);