Skip to content

Commit

Permalink
push: fix --dry-run to not push submodules
Browse files Browse the repository at this point in the history
Teach push to respect the --dry-run option when configured to
recursively push submodules 'on-demand'.  This is done by passing the
--dry-run flag to the child process which performs a push for a
submodules when performing a dry-run.

In order to preserve good user experience, the additional check for
unpushed submodules is skipped during a dry-run when
--recurse-submodules=on-demand.  The check is skipped because the submodule
pushes were performed as dry-runs and this check would always fail as the
submodules would still need to be pushed.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
bmwill authored and gitster committed Nov 23, 2016
1 parent 1aa7365 commit 0301c82
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
13 changes: 8 additions & 5 deletions submodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,16 +683,17 @@ int find_unpushed_submodules(struct sha1_array *commits,
return needs_pushing->nr;
}

static int push_submodule(const char *path)
static int push_submodule(const char *path, int dry_run)
{
if (add_submodule_odb(path))
return 1;

if (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) {
struct child_process cp = CHILD_PROCESS_INIT;
const char *argv[] = {"push", NULL};
argv_array_push(&cp.args, "push");
if (dry_run)
argv_array_push(&cp.args, "--dry-run");

cp.argv = argv;
prepare_submodule_repo_env(&cp.env_array);
cp.git_cmd = 1;
cp.no_stdin = 1;
Expand All @@ -705,7 +706,9 @@ static int push_submodule(const char *path)
return 1;
}

int push_unpushed_submodules(struct sha1_array *commits, const char *remotes_name)
int push_unpushed_submodules(struct sha1_array *commits,
const char *remotes_name,
int dry_run)
{
int i, ret = 1;
struct string_list needs_pushing = STRING_LIST_INIT_DUP;
Expand All @@ -716,7 +719,7 @@ int push_unpushed_submodules(struct sha1_array *commits, const char *remotes_nam
for (i = 0; i < needs_pushing.nr; i++) {
const char *path = needs_pushing.items[i].string;
fprintf(stderr, "Pushing submodule '%s'\n", path);
if (!push_submodule(path)) {
if (!push_submodule(path, dry_run)) {
fprintf(stderr, "Unable to push submodule '%s'\n", path);
ret = 0;
}
Expand Down
4 changes: 3 additions & 1 deletion submodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ int merge_submodule(unsigned char result[20], const char *path, const unsigned c
const unsigned char a[20], const unsigned char b[20], int search);
int find_unpushed_submodules(struct sha1_array *commits, const char *remotes_name,
struct string_list *needs_pushing);
int push_unpushed_submodules(struct sha1_array *commits, const char *remotes_name);
extern int push_unpushed_submodules(struct sha1_array *commits,
const char *remotes_name,
int dry_run);
void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
int parallel_submodules(void);

Expand Down
2 changes: 1 addition & 1 deletion t/t5531-deep-submodule-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ test_expect_success 'push unpushable submodule recursively fails' '
test_cmp expected actual
'

test_expect_failure 'push --dry-run does not recursively update submodules' '
test_expect_success 'push --dry-run does not recursively update submodules' '
(
cd work/gar/bage &&
git checkout master &&
Expand Down
9 changes: 6 additions & 3 deletions transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -921,15 +921,18 @@ int transport_push(struct transport *transport,
if (!is_null_oid(&ref->new_oid))
sha1_array_append(&commits, ref->new_oid.hash);

if (!push_unpushed_submodules(&commits, transport->remote->name)) {
if (!push_unpushed_submodules(&commits,
transport->remote->name,
pretend)) {
sha1_array_clear(&commits);
die("Failed to push all needed submodules!");
}
sha1_array_clear(&commits);
}

if ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
TRANSPORT_RECURSE_SUBMODULES_CHECK)) && !is_bare_repository()) {
if (((flags & TRANSPORT_RECURSE_SUBMODULES_CHECK) ||
((flags & TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND) &&
!pretend)) && !is_bare_repository()) {
struct ref *ref = remote_refs;
struct string_list needs_pushing = STRING_LIST_INIT_DUP;
struct sha1_array commits = SHA1_ARRAY_INIT;
Expand Down

0 comments on commit 0301c82

Please sign in to comment.