summaryrefslogtreecommitdiff
path: root/builtin/checkout.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/checkout.c')
-rw-r--r--builtin/checkout.c60
1 files changed, 48 insertions, 12 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c
index c15dc91..4989ca7 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -34,6 +34,11 @@ static const char * const checkout_usage[] = {
NULL,
};
+static const char * const switch_branch_usage[] = {
+ N_("git switch [<options>] [<branch>]"),
+ NULL,
+};
+
struct checkout_opts {
int patch_mode;
int quiet;
@@ -1411,33 +1416,25 @@ static struct option *add_checkout_path_options(struct checkout_opts *opts,
return newopts;
}
-int cmd_checkout(int argc, const char **argv, const char *prefix)
+static int checkout_main(int argc, const char **argv, const char *prefix,
+ struct checkout_opts *opts, struct option *options,
+ const char * const usagestr[])
{
- struct checkout_opts real_opts;
- struct checkout_opts *opts = &real_opts;
struct branch_info new_branch_info;
int dwim_remotes_matched = 0;
int dwim_new_local_branch;
- struct option *options = NULL;
- memset(opts, 0, sizeof(*opts));
memset(&new_branch_info, 0, sizeof(new_branch_info));
opts->overwrite_ignore = 1;
opts->prefix = prefix;
opts->show_progress = -1;
opts->overlay_mode = -1;
- opts->no_dwim_new_local_branch = 0;
git_config(git_checkout_config, opts);
opts->track = BRANCH_TRACK_UNSPECIFIED;
- options = parse_options_dup(options);
- options = add_common_options(opts, options);
- options = add_switch_branch_options(opts, options);
- options = add_checkout_path_options(opts, options);
-
- argc = parse_options(argc, argv, prefix, options, checkout_usage,
+ argc = parse_options(argc, argv, prefix, options, usagestr,
PARSE_OPT_KEEP_DASHDASH);
dwim_new_local_branch = !opts->no_dwim_new_local_branch;
@@ -1570,3 +1567,42 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
return checkout_branch(opts, &new_branch_info);
}
}
+
+int cmd_checkout(int argc, const char **argv, const char *prefix)
+{
+ struct checkout_opts opts;
+ struct option *options = NULL;
+ int ret;
+
+ memset(&opts, 0, sizeof(opts));
+ opts.no_dwim_new_local_branch = 0;
+
+ options = parse_options_dup(options);
+ options = add_common_options(&opts, options);
+ options = add_switch_branch_options(&opts, options);
+ options = add_checkout_path_options(&opts, options);
+
+ ret = checkout_main(argc, argv, prefix, &opts,
+ options, checkout_usage);
+ FREE_AND_NULL(options);
+ return ret;
+}
+
+int cmd_switch(int argc, const char **argv, const char *prefix)
+{
+ struct checkout_opts opts;
+ struct option *options = NULL;
+ int ret;
+
+ memset(&opts, 0, sizeof(opts));
+ opts.no_dwim_new_local_branch = 0;
+
+ options = parse_options_dup(options);
+ options = add_common_options(&opts, options);
+ options = add_switch_branch_options(&opts, options);
+
+ ret = checkout_main(argc, argv, prefix, &opts,
+ options, switch_branch_usage);
+ FREE_AND_NULL(options);
+ return ret;
+}