builtin/reset: add --recurse-submodules switch
git-reset is yet another working tree manipulator, which should be taught about submodules. When a user uses git-reset and requests to recurse into submodules, this will reset the submodules to the object name as recorded in the superproject, detaching the HEADs. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
f2d48994dc
commit
35b96d1de8
@ -21,6 +21,27 @@
|
||||
#include "parse-options.h"
|
||||
#include "unpack-trees.h"
|
||||
#include "cache-tree.h"
|
||||
#include "submodule.h"
|
||||
#include "submodule-config.h"
|
||||
|
||||
static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
|
||||
|
||||
static int option_parse_recurse_submodules(const struct option *opt,
|
||||
const char *arg, int unset)
|
||||
{
|
||||
if (unset) {
|
||||
recurse_submodules = RECURSE_SUBMODULES_OFF;
|
||||
return 0;
|
||||
}
|
||||
if (arg)
|
||||
recurse_submodules =
|
||||
parse_update_recurse_submodules_arg(opt->long_name,
|
||||
arg);
|
||||
else
|
||||
recurse_submodules = RECURSE_SUBMODULES_ON;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char * const git_reset_usage[] = {
|
||||
N_("git reset [--mixed | --soft | --hard | --merge | --keep] [-q] [<commit>]"),
|
||||
@ -283,6 +304,9 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
|
||||
N_("reset HEAD, index and working tree"), MERGE),
|
||||
OPT_SET_INT(0, "keep", &reset_type,
|
||||
N_("reset HEAD but keep local changes"), KEEP),
|
||||
{ OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules,
|
||||
"reset", "control recursive updating of submodules",
|
||||
PARSE_OPT_OPTARG, option_parse_recurse_submodules },
|
||||
OPT_BOOL('p', "patch", &patch_mode, N_("select hunks interactively")),
|
||||
OPT_BOOL('N', "intent-to-add", &intent_to_add,
|
||||
N_("record only the fact that removed paths will be added later")),
|
||||
@ -295,6 +319,12 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
|
||||
PARSE_OPT_KEEP_DASHDASH);
|
||||
parse_args(&pathspec, argv, prefix, patch_mode, &rev);
|
||||
|
||||
if (recurse_submodules != RECURSE_SUBMODULES_DEFAULT) {
|
||||
gitmodules_config();
|
||||
git_config(submodule_config, NULL);
|
||||
set_config_update_recurse_submodules(RECURSE_SUBMODULES_ON);
|
||||
}
|
||||
|
||||
unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", oid.hash);
|
||||
if (unborn) {
|
||||
/* reset on unborn branch: treat as reset to empty tree */
|
||||
|
@ -5,6 +5,14 @@ test_description='reset can handle submodules'
|
||||
. ./test-lib.sh
|
||||
. "$TEST_DIRECTORY"/lib-submodule-update.sh
|
||||
|
||||
KNOWN_FAILURE_SUBMODULE_RECURSIVE_NESTED=1
|
||||
KNOWN_FAILURE_DIRECTORY_SUBMODULE_CONFLICTS=1
|
||||
KNOWN_FAILURE_SUBMODULE_OVERWRITE_IGNORED_UNTRACKED=1
|
||||
|
||||
test_submodule_switch_recursing "git reset --recurse-submodules --keep"
|
||||
|
||||
test_submodule_forced_switch_recursing "git reset --hard --recurse-submodules"
|
||||
|
||||
test_submodule_switch "git reset --keep"
|
||||
|
||||
test_submodule_switch "git reset --merge"
|
||||
|
Loading…
Reference in New Issue
Block a user