Skip to content

Commit dd3b512

Browse files
committed
DEPRECATION: warn about 'git checkout -b'
Recommend that users use 'git switch -c' instead. Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
1 parent 538420f commit dd3b512

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

builtin/.checkout.c.swp

-76 KB
Binary file not shown.

builtin/checkout.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,7 @@ static int switch_branches(const struct checkout_opts *opts,
11331133
void *path_to_free;
11341134
struct object_id rev;
11351135
int flag, writeout_error = 0;
1136+
int do_merge = 1;
11361137

11371138
trace2_cmd_mode("branch");
11381139

@@ -1159,15 +1160,20 @@ static int switch_branches(const struct checkout_opts *opts,
11591160
if (!new_branch_info->commit)
11601161
die(_("You are on a branch yet to be born"));
11611162
parse_commit_or_die(new_branch_info->commit);
1163+
1164+
if (opts->only_merge_on_switching_branches)
1165+
do_merge = 0;
11621166
}
11631167

11641168
/* optimize the "checkout -b <new_branch> path */
1165-
if (skip_merge_working_tree(opts, &old_branch_info, new_branch_info)) {
1169+
if (!do_merge || skip_merge_working_tree(opts, &old_branch_info, new_branch_info)) {
11661170
if (!checkout_optimize_new_branch && !opts->quiet) {
11671171
if (read_cache_preload(NULL) < 0)
11681172
return error(_("index file corrupt"));
11691173
show_local_changes(&new_branch_info->commit->object, &opts->diff_options);
11701174
}
1175+
if (!opts->only_merge_on_switching_branches)
1176+
warning(_("'git checkout -b <new-branch>' is being deprecated in favor of 'git switch -c <new-branch>'. Please adjust your workflow accordingly."));
11711177
} else {
11721178
ret = merge_working_tree(opts, &old_branch_info, new_branch_info, &writeout_error);
11731179
if (ret) {
@@ -1867,6 +1873,7 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
18671873
opts.accept_ref = 1;
18681874
opts.accept_pathspec = 0;
18691875
opts.switch_branch_doing_nothing_is_ok = 0;
1876+
opts.only_merge_on_switching_branches = 1;
18701877
opts.implicit_detach = 0;
18711878
opts.can_switch_when_in_progress = 0;
18721879
opts.orphan_from_empty_tree = 1;

0 commit comments

Comments
 (0)