push: add option to push only submodules

Teach push the --recurse-submodules=only option.  This enables push
to recursively push all unpushed submodules while leaving the
superproject unpushed.

This is a desirable feature in a scenario where updates to the
superproject are handled automatically by some other means, perhaps
a tool like Gerrit code review.  In this scenario, a developer could
make a change which spans multiple submodules and then push their
commits for code review.  Upon completion of the code review, their
commits can be accepted and applied to their respective submodules
while the code review tool can then automatically update the
superproject to the most recent SHA1 of each submodule.  This would
reduce the merge conflicts in the superproject that could occur if
multiple people are contributing to the same submodule.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Brandon Williams 2016-12-19 10:25:33 -08:00 коммит произвёл Junio C Hamano
Родитель 6c656c3fe4
Коммит 225e8bf778
4 изменённых файлов: 35 добавлений и 4 удалений

Просмотреть файл

@ -565,6 +565,8 @@ int cmd_push(int argc, const char **argv, const char *prefix)
flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)
flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND;
else if (recurse_submodules == RECURSE_SUBMODULES_ONLY)
flags |= TRANSPORT_RECURSE_SUBMODULES_ONLY;
if (tags)
add_refspec("refs/tags/*");

Просмотреть файл

@ -454,4 +454,25 @@ test_expect_success 'push --dry-run does not recursively update submodules' '
test_cmp expected_submodule actual_submodule
'
test_expect_success 'push --dry-run does not recursively update submodules' '
git -C work push --dry-run --recurse-submodules=only ../pub.git master &&
git -C submodule.git rev-parse master >actual_submodule &&
git -C pub.git rev-parse master >actual_pub &&
test_cmp expected_pub actual_pub &&
test_cmp expected_submodule actual_submodule
'
test_expect_success 'push only unpushed submodules recursively' '
git -C work/gar/bage rev-parse master >expected_submodule &&
git -C pub.git rev-parse master >expected_pub &&
git -C work push --recurse-submodules=only ../pub.git master &&
git -C submodule.git rev-parse master >actual_submodule &&
git -C pub.git rev-parse master >actual_pub &&
test_cmp expected_submodule actual_submodule &&
test_cmp expected_pub actual_pub
'
test_done

Просмотреть файл

@ -947,7 +947,9 @@ int transport_push(struct transport *transport,
if (run_pre_push_hook(transport, remote_refs))
return -1;
if ((flags & TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND) && !is_bare_repository()) {
if ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
TRANSPORT_RECURSE_SUBMODULES_ONLY)) &&
!is_bare_repository()) {
struct ref *ref = remote_refs;
struct sha1_array commits = SHA1_ARRAY_INIT;
@ -965,7 +967,8 @@ int transport_push(struct transport *transport,
}
if (((flags & TRANSPORT_RECURSE_SUBMODULES_CHECK) ||
((flags & TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND) &&
((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
TRANSPORT_RECURSE_SUBMODULES_ONLY)) &&
!pretend)) && !is_bare_repository()) {
struct ref *ref = remote_refs;
struct string_list needs_pushing = STRING_LIST_INIT_DUP;
@ -984,7 +987,10 @@ int transport_push(struct transport *transport,
sha1_array_clear(&commits);
}
push_ret = transport->push_refs(transport, remote_refs, flags);
if (!(flags & TRANSPORT_RECURSE_SUBMODULES_ONLY))
push_ret = transport->push_refs(transport, remote_refs, flags);
else
push_ret = 0;
err = push_had_errors(remote_refs);
ret = push_ret | err;
@ -996,7 +1002,8 @@ int transport_push(struct transport *transport,
if (flags & TRANSPORT_PUSH_SET_UPSTREAM)
set_upstreams(transport, remote_refs, pretend);
if (!(flags & TRANSPORT_PUSH_DRY_RUN)) {
if (!(flags & (TRANSPORT_PUSH_DRY_RUN |
TRANSPORT_RECURSE_SUBMODULES_ONLY))) {
struct ref *ref;
for (ref = remote_refs; ref; ref = ref->next)
transport_update_tracking_ref(transport->remote, ref, verbose);

Просмотреть файл

@ -146,6 +146,7 @@ struct transport {
#define TRANSPORT_PUSH_CERT_IF_ASKED (1<<12)
#define TRANSPORT_PUSH_ATOMIC (1<<13)
#define TRANSPORT_PUSH_OPTIONS (1<<14)
#define TRANSPORT_RECURSE_SUBMODULES_ONLY (1<<15)
extern int transport_summary_width(const struct ref *refs);