Merge branch 'bw/push-submodule-only'

"git submodule push" learned "--recurse-submodules=only option to
push submodules out without pushing the top-level superproject.

* bw/push-submodule-only:
  push: add option to push only submodules
  submodules: add RECURSE_SUBMODULES_ONLY value
  transport: reformat flag #defines to be more readable
This commit is contained in:
Junio C Hamano 2017-01-31 13:14:56 -08:00
Родитель daf75f2e6b 225e8bf778
Коммит 792e22e3fd
6 изменённых файлов: 53 добавлений и 19 удалений

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

@ -568,6 +568,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/*");

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

@ -251,6 +251,8 @@ static int parse_push_recurse(const char *opt, const char *arg,
return RECURSE_SUBMODULES_ON_DEMAND;
else if (!strcmp(arg, "check"))
return RECURSE_SUBMODULES_CHECK;
else if (!strcmp(arg, "only"))
return RECURSE_SUBMODULES_ONLY;
else if (die_on_error)
die("bad %s argument: %s", opt, arg);
else

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

@ -6,6 +6,7 @@ struct argv_array;
struct sha1_array;
enum {
RECURSE_SUBMODULES_ONLY = -5,
RECURSE_SUBMODULES_CHECK = -4,
RECURSE_SUBMODULES_ERROR = -3,
RECURSE_SUBMODULES_NONE = -2,

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

@ -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

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

@ -1015,7 +1015,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;
@ -1033,7 +1035,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;
@ -1052,7 +1055,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;
@ -1064,7 +1070,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);

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

@ -131,21 +131,22 @@ struct transport {
enum transport_family family;
};
#define TRANSPORT_PUSH_ALL 1
#define TRANSPORT_PUSH_FORCE 2
#define TRANSPORT_PUSH_DRY_RUN 4
#define TRANSPORT_PUSH_MIRROR 8
#define TRANSPORT_PUSH_PORCELAIN 16
#define TRANSPORT_PUSH_SET_UPSTREAM 32
#define TRANSPORT_RECURSE_SUBMODULES_CHECK 64
#define TRANSPORT_PUSH_PRUNE 128
#define TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND 256
#define TRANSPORT_PUSH_NO_HOOK 512
#define TRANSPORT_PUSH_FOLLOW_TAGS 1024
#define TRANSPORT_PUSH_CERT_ALWAYS 2048
#define TRANSPORT_PUSH_CERT_IF_ASKED 4096
#define TRANSPORT_PUSH_ATOMIC 8192
#define TRANSPORT_PUSH_OPTIONS 16384
#define TRANSPORT_PUSH_ALL (1<<0)
#define TRANSPORT_PUSH_FORCE (1<<1)
#define TRANSPORT_PUSH_DRY_RUN (1<<2)
#define TRANSPORT_PUSH_MIRROR (1<<3)
#define TRANSPORT_PUSH_PORCELAIN (1<<4)
#define TRANSPORT_PUSH_SET_UPSTREAM (1<<5)
#define TRANSPORT_RECURSE_SUBMODULES_CHECK (1<<6)
#define TRANSPORT_PUSH_PRUNE (1<<7)
#define TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND (1<<8)
#define TRANSPORT_PUSH_NO_HOOK (1<<9)
#define TRANSPORT_PUSH_FOLLOW_TAGS (1<<10)
#define TRANSPORT_PUSH_CERT_ALWAYS (1<<11)
#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);