Skip to content

Commit e4b2ad7

Browse files
committed
Merge branch 'sb/push-make-submodule-check-the-default' into pu
Turn the default of "push.recurseSubmodules" to "check" when submodules seem to be in use. * sb/push-make-submodule-check-the-default: push: change submodule default to check when submodules exist submodule add: extend force flag to add existing repos
2 parents 1002f22 + 38a8308 commit e4b2ad7

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

builtin/push.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
#include "cache.h"
55
#include "refs.h"
6+
#include "dir.h"
67
#include "run-command.h"
78
#include "builtin.h"
89
#include "remote.h"
@@ -22,6 +23,7 @@ static int deleterefs;
2223
static const char *receivepack;
2324
static int verbosity;
2425
static int progress = -1;
26+
static int has_submodules_configured;
2527
static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
2628
static enum transport_family family;
2729

@@ -31,6 +33,15 @@ static const char **refspec;
3133
static int refspec_nr;
3234
static int refspec_alloc;
3335

36+
static void preset_submodule_default(void)
37+
{
38+
if (has_submodules_configured || file_exists(git_path("modules")) ||
39+
(!is_bare_repository() && file_exists(".gitmodules")))
40+
recurse_submodules = RECURSE_SUBMODULES_CHECK;
41+
else
42+
recurse_submodules = RECURSE_SUBMODULES_OFF;
43+
}
44+
3445
static void add_refspec(const char *ref)
3546
{
3647
refspec_nr++;
@@ -495,7 +506,8 @@ static int git_push_config(const char *k, const char *v, void *cb)
495506
const char *value;
496507
if (!git_config_get_value("push.recursesubmodules", &value))
497508
recurse_submodules = parse_push_recurse_submodules_arg(k, value);
498-
}
509+
} else if (starts_with(k, "submodule.") && ends_with(k, ".url"))
510+
has_submodules_configured = 1;
499511

500512
return git_default_config(k, v, NULL);
501513
}
@@ -552,6 +564,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
552564
};
553565

554566
packet_trace_identity("push");
567+
preset_submodule_default();
555568
git_config(git_push_config, &flags);
556569
argc = parse_options(argc, argv, prefix, options, push_usage, 0);
557570
set_push_cert_flags(&flags, push_cert);

git-submodule.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,14 @@ cmd_add()
207207
tstart
208208
s|/*$||
209209
')
210-
git ls-files --error-unmatch "$sm_path" > /dev/null 2>&1 &&
211-
die "$(eval_gettext "'\$sm_path' already exists in the index")"
210+
if test -z "$force"
211+
then
212+
git ls-files --error-unmatch "$sm_path" > /dev/null 2>&1 &&
213+
die "$(eval_gettext "'\$sm_path' already exists in the index")"
214+
else
215+
git ls-files -s "$sm_path" | sane_grep -v "^160000" > /dev/null 2>&1 &&
216+
die "$(eval_gettext "'\$sm_path' already exists in the index and is not a submodule")"
217+
fi
212218

213219
if test -z "$force" && ! git add --dry-run --ignore-missing "$sm_path" > /dev/null 2>&1
214220
then

t/t5531-deep-submodule-push.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ test_expect_success 'push fails if submodule commit not on remote' '
6565
git add gar/bage &&
6666
git commit -m "Third commit for gar/bage" &&
6767
# the push should fail with --recurse-submodules=check
68-
# on the command line...
68+
# on the command line. "check" is the default for repos in
69+
# which submodules are detected by existence of config,
70+
# .gitmodules file or an internal .git/modules/<submodule-repo>
71+
git submodule add -f ../submodule.git gar/bage &&
72+
test_must_fail git push ../pub.git master &&
6973
test_must_fail git push --recurse-submodules=check ../pub.git master &&
7074
7175
# ...or if specified in the configuration..

t/t7400-submodule-basic.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,20 @@ test_expect_success 'submodule add to .gitignored path with --force' '
152152
)
153153
'
154154

155+
test_expect_success 'submodule add to reconfigure existing submodule with --force' '
156+
(
157+
cd addtest-ignore &&
158+
git submodule add --force bogus-url submod &&
159+
git submodule add -b initial "$submodurl" submod-branch &&
160+
test "bogus-url" = "$(git config -f .gitmodules submodule.submod.url)" &&
161+
test "bogus-url" = "$(git config submodule.submod.url)" &&
162+
# Restore the url
163+
git submodule add --force "$submodurl" submod
164+
test "$submodurl" = "$(git config -f .gitmodules submodule.submod.url)" &&
165+
test "$submodurl" = "$(git config submodule.submod.url)"
166+
)
167+
'
168+
155169
test_expect_success 'submodule add --branch' '
156170
echo "refs/heads/initial" >expect-head &&
157171
cat <<-\EOF >expect-heads &&

0 commit comments

Comments
 (0)