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>
Stefan Beller committed
Apr 21, 2017 at 10:39 UTC
35b96d1de8e795aeac8ec281e88e59f2778335e7
2 files changed
+38
builtin/reset.c
+30
@@ -21,6 +21,27 @@
21
#include "parse-options.h"
22
#include "unpack-trees.h"
23
#include "cache-tree.h"
24
+#include "submodule.h"
25
+#include "submodule-config.h"
26
+
27
+static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
28
+
29
+static int option_parse_recurse_submodules(const struct option *opt,
30
+ const char *arg, int unset)
31
+{
32
+ if (unset) {
33
+ recurse_submodules = RECURSE_SUBMODULES_OFF;
34
+ return 0;
35
+ }
36
+ if (arg)
37
+ recurse_submodules =
38
+ parse_update_recurse_submodules_arg(opt->long_name,
39
+ arg);
40
+ else
41
+ recurse_submodules = RECURSE_SUBMODULES_ON;
42
+
43
+ return 0;
44
+}
45
46
static const char * const git_reset_usage[] = {
47
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)
304
N_("reset HEAD, index and working tree"), MERGE),
305
OPT_SET_INT(0, "keep", &reset_type,
306
N_("reset HEAD but keep local changes"), KEEP),
307
+ { OPTION_CALLBACK, 0, "recurse-submodules", &recurse_submodules,
308
+ "reset", "control recursive updating of submodules",
309
+ PARSE_OPT_OPTARG, option_parse_recurse_submodules },
310
OPT_BOOL('p', "patch", &patch_mode, N_("select hunks interactively")),
311
OPT_BOOL('N', "intent-to-add", &intent_to_add,
312
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)
319
PARSE_OPT_KEEP_DASHDASH);
320
parse_args(&pathspec, argv, prefix, patch_mode, &rev);
321
322
+ if (recurse_submodules != RECURSE_SUBMODULES_DEFAULT) {
323
+ gitmodules_config();
324
+ git_config(submodule_config, NULL);
325
+ set_config_update_recurse_submodules(RECURSE_SUBMODULES_ON);
326
+ }
327
+
328
unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", oid.hash);
329
if (unborn) {
330
/* reset on unborn branch: treat as reset to empty tree */
t/t7112-reset-submodule.sh
+8
@@ -5,6 +5,14 @@ test_description='reset can handle submodules'
5
. ./test-lib.sh
6
. "$TEST_DIRECTORY"/lib-submodule-update.sh
7
8
+KNOWN_FAILURE_SUBMODULE_RECURSIVE_NESTED=1
9
+KNOWN_FAILURE_DIRECTORY_SUBMODULE_CONFLICTS=1
10
+KNOWN_FAILURE_SUBMODULE_OVERWRITE_IGNORED_UNTRACKED=1
11
+
12
+test_submodule_switch_recursing "git reset --recurse-submodules --keep"
13
+
14
+test_submodule_forced_switch_recursing "git reset --hard --recurse-submodules"
15
+
16
test_submodule_switch "git reset --keep"
17
18
test_submodule_switch "git reset --merge"