Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2019-03-29 13:39:05 +0300
committerJunio C Hamano <gitster@pobox.com>2019-04-02 07:56:59 +0300
commitd787d311dbd7a4104a9dde23b90ae24528a15cf9 (patch)
tree230257b33d63907678d78b903ac8d75585dd7cc9 /builtin/checkout.c
parent208718227207480b0f58e35e045e36ed36a59205 (diff)
checkout: split part of it to new command 'switch'
"git checkout" doing too many things is a source of confusion for many users (and it even bites old timers sometimes). To remedy that, the command will be split into two new ones: switch and restore. The good old "git checkout" command is still here and will be until all (or most of users) are sick of it. See the new man page for the final design of switch. The actual implementation though is still pretty much the same as "git checkout" and not completely aligned with the man page. Following patches will adjust their behavior to match the man page. 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.c60
1 files changed, 48 insertions, 12 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c
index c15dc91e16..4989ca73a3 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;
+}