24
#include "tree.h"
25
#include "tree-walk.h"
26
#include "unpack-trees.h"
27
+#include "wt-status.h"
28
#include "xdiff-interface.h"
29
30
static const char * const checkout_usage[] = {
57
int accept_pathspec;
58
int switch_branch_doing_nothing_is_ok;
59
int only_merge_on_switching_branches;
60
+ int can_switch_when_in_progress;
61
62
const char *new_branch;
63
const char *new_branch_force;
1204
die(_("a branch is expected, got '%s'"), branch_info->name);
1205
}
1206
1207
+static void die_if_some_operation_in_progress(void)
1208
+{
1209
+ struct wt_status_state state;
1210
+
1211
+ memset(&state, 0, sizeof(state));
1212
+ wt_status_get_state(the_repository, &state, 0);
1213
+
1214
+ if (state.merge_in_progress)
1215
+ die(_("cannot switch branch while merging\n"
1216
+ "Consider \"git merge --quit\" "
1217
+ "or \"git worktree add\"."));
1218
+ if (state.am_in_progress)
1219
+ die(_("cannot switch branch in the middle of an am session\n"
1220
+ "Consider \"git am --quit\" "
1221
+ "or \"git worktree add\"."));
1222
+ if (state.rebase_interactive_in_progress || state.rebase_in_progress)
1223
+ die(_("cannot switch branch while rebasing\n"
1224
+ "Consider \"git rebase --quit\" "
1225
+ "or \"git worktree add\"."));
1226
+ if (state.cherry_pick_in_progress)
1227
+ die(_("cannot switch branch while cherry-picking\n"
1228
+ "Consider \"git cherry-pick --quit\" "
1229
+ "or \"git worktree add\"."));
1230
+ if (state.revert_in_progress)
1231
+ die(_("cannot switch branch while reverting\n"
1232
+ "Consider \"git revert --quit\" "
1233
+ "or \"git worktree add\"."));
1234
+ if (state.bisect_in_progress)
1235
+ die(_("cannot switch branch while bisecting\n"
1236
+ "Consider \"git bisect reset HEAD\" "
1237
+ "or \"git worktree add\"."));
1238
+}
1239
+
1240
static int checkout_branch(struct checkout_opts *opts,
1241
struct branch_info *new_branch_info)
1242
{
1292
!new_branch_info->path)
1293
die_expecting_a_branch(new_branch_info);
1294
1295
+ if (!opts->can_switch_when_in_progress)
1296
+ die_if_some_operation_in_progress();
1297
+
1298
if (new_branch_info->path && !opts->force_detach && !opts->new_branch &&
1299
!opts->ignore_other_worktrees) {
1300
int flag;
1552
opts.only_merge_on_switching_branches = 0;
1553
opts.accept_pathspec = 1;
1554
opts.implicit_detach = 1;
1555
+ opts.can_switch_when_in_progress = 1;
1556
1557
options = parse_options_dup(checkout_options);
1558
options = add_common_options(&opts, options);
1588
opts.switch_branch_doing_nothing_is_ok = 0;
1589
opts.only_merge_on_switching_branches = 1;
1590
opts.implicit_detach = 0;
1591
+ opts.can_switch_when_in_progress = 0;
1592
1593
options = parse_options_dup(switch_options);
1594
options = add_common_options(&opts, options);