|
|
|
@ -1702,10 +1702,11 @@ static char cb_option = 'b';
|
|
|
|
|
|
|
|
|
|
static int checkout_main(int argc, const char **argv, const char *prefix,
|
|
|
|
|
struct checkout_opts *opts, struct option *options,
|
|
|
|
|
const char * const usagestr[],
|
|
|
|
|
struct branch_info *new_branch_info)
|
|
|
|
|
const char * const usagestr[])
|
|
|
|
|
{
|
|
|
|
|
int parseopt_flags = 0;
|
|
|
|
|
struct branch_info new_branch_info = { 0 };
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
opts->overwrite_ignore = 1;
|
|
|
|
|
opts->prefix = prefix;
|
|
|
|
@ -1821,7 +1822,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
|
|
|
|
|
opts->track == BRANCH_TRACK_UNSPECIFIED &&
|
|
|
|
|
!opts->new_branch;
|
|
|
|
|
int n = parse_branchname_arg(argc, argv, dwim_ok,
|
|
|
|
|
new_branch_info, opts, &rev);
|
|
|
|
|
&new_branch_info, opts, &rev);
|
|
|
|
|
argv += n;
|
|
|
|
|
argc -= n;
|
|
|
|
|
} else if (!opts->accept_ref && opts->from_treeish) {
|
|
|
|
@ -1830,7 +1831,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
|
|
|
|
|
if (repo_get_oid_mb(the_repository, opts->from_treeish, &rev))
|
|
|
|
|
die(_("could not resolve %s"), opts->from_treeish);
|
|
|
|
|
|
|
|
|
|
setup_new_branch_info_and_source_tree(new_branch_info,
|
|
|
|
|
setup_new_branch_info_and_source_tree(&new_branch_info,
|
|
|
|
|
opts, &rev,
|
|
|
|
|
opts->from_treeish);
|
|
|
|
|
|
|
|
|
@ -1850,7 +1851,7 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
|
|
|
|
|
* Try to give more helpful suggestion.
|
|
|
|
|
* new_branch && argc > 1 will be caught later.
|
|
|
|
|
*/
|
|
|
|
|
if (opts->new_branch && argc == 1 && !new_branch_info->commit)
|
|
|
|
|
if (opts->new_branch && argc == 1 && !new_branch_info.commit)
|
|
|
|
|
die(_("'%s' is not a commit and a branch '%s' cannot be created from it"),
|
|
|
|
|
argv[0], opts->new_branch);
|
|
|
|
|
|
|
|
|
@ -1900,9 +1901,16 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (opts->patch_mode || opts->pathspec.nr)
|
|
|
|
|
return checkout_paths(opts, new_branch_info);
|
|
|
|
|
ret = checkout_paths(opts, &new_branch_info);
|
|
|
|
|
else
|
|
|
|
|
return checkout_branch(opts, new_branch_info);
|
|
|
|
|
ret = checkout_branch(opts, &new_branch_info);
|
|
|
|
|
|
|
|
|
|
branch_info_release(&new_branch_info);
|
|
|
|
|
clear_pathspec(&opts->pathspec);
|
|
|
|
|
free(opts->pathspec_from_file);
|
|
|
|
|
free(options);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int cmd_checkout(int argc, const char **argv, const char *prefix)
|
|
|
|
@ -1920,8 +1928,6 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
|
|
|
|
|
OPT_BOOL(0, "overlay", &opts.overlay_mode, N_("use overlay mode (default)")),
|
|
|
|
|
OPT_END()
|
|
|
|
|
};
|
|
|
|
|
int ret;
|
|
|
|
|
struct branch_info new_branch_info = { 0 };
|
|
|
|
|
|
|
|
|
|
memset(&opts, 0, sizeof(opts));
|
|
|
|
|
opts.dwim_new_local_branch = 1;
|
|
|
|
@ -1951,13 +1957,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
|
|
|
|
|
options = add_common_switch_branch_options(&opts, options);
|
|
|
|
|
options = add_checkout_path_options(&opts, options);
|
|
|
|
|
|
|
|
|
|
ret = checkout_main(argc, argv, prefix, &opts,
|
|
|
|
|
options, checkout_usage, &new_branch_info);
|
|
|
|
|
branch_info_release(&new_branch_info);
|
|
|
|
|
clear_pathspec(&opts.pathspec);
|
|
|
|
|
free(opts.pathspec_from_file);
|
|
|
|
|
FREE_AND_NULL(options);
|
|
|
|
|
return ret;
|
|
|
|
|
return checkout_main(argc, argv, prefix, &opts, options,
|
|
|
|
|
checkout_usage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int cmd_switch(int argc, const char **argv, const char *prefix)
|
|
|
|
@ -1975,8 +1976,6 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
|
|
|
|
|
N_("throw away local modifications")),
|
|
|
|
|
OPT_END()
|
|
|
|
|
};
|
|
|
|
|
int ret;
|
|
|
|
|
struct branch_info new_branch_info = { 0 };
|
|
|
|
|
|
|
|
|
|
memset(&opts, 0, sizeof(opts));
|
|
|
|
|
opts.dwim_new_local_branch = 1;
|
|
|
|
@ -1995,11 +1994,8 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
|
|
|
|
|
|
|
|
|
|
cb_option = 'c';
|
|
|
|
|
|
|
|
|
|
ret = checkout_main(argc, argv, prefix, &opts,
|
|
|
|
|
options, switch_branch_usage, &new_branch_info);
|
|
|
|
|
branch_info_release(&new_branch_info);
|
|
|
|
|
FREE_AND_NULL(options);
|
|
|
|
|
return ret;
|
|
|
|
|
return checkout_main(argc, argv, prefix, &opts, options,
|
|
|
|
|
switch_branch_usage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int cmd_restore(int argc, const char **argv, const char *prefix)
|
|
|
|
@ -2018,8 +2014,6 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
|
|
|
|
|
OPT_BOOL(0, "overlay", &opts.overlay_mode, N_("use overlay mode")),
|
|
|
|
|
OPT_END()
|
|
|
|
|
};
|
|
|
|
|
int ret;
|
|
|
|
|
struct branch_info new_branch_info = { 0 };
|
|
|
|
|
|
|
|
|
|
memset(&opts, 0, sizeof(opts));
|
|
|
|
|
opts.accept_ref = 0;
|
|
|
|
@ -2034,9 +2028,6 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
|
|
|
|
|
options = add_common_options(&opts, options);
|
|
|
|
|
options = add_checkout_path_options(&opts, options);
|
|
|
|
|
|
|
|
|
|
ret = checkout_main(argc, argv, prefix, &opts,
|
|
|
|
|
options, restore_usage, &new_branch_info);
|
|
|
|
|
branch_info_release(&new_branch_info);
|
|
|
|
|
FREE_AND_NULL(options);
|
|
|
|
|
return ret;
|
|
|
|
|
return checkout_main(argc, argv, prefix, &opts, options,
|
|
|
|
|
restore_usage);
|
|
|
|
|
}
|
|
|
|
|