push: propagate push-options with --recurse-submodules
Teach push --recurse-submodules to propagate push-options recursively to the pushes performed in the submodules. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Williams committed
Apr 5, 2017 at 10:47 UTC
2a90556dde47f27e12a3f8adb1397fd05e5b6690
4 files changed
+53
-2
submodule.c
+11
-2
@@ -782,7 +782,9 @@ int find_unpushed_submodules(struct sha1_array *commits,
782
return needs_pushing->nr;
783
}
784
785
-static int push_submodule(const char *path, int dry_run)
785
+static int push_submodule(const char *path,
786
+ const struct string_list *push_options,
787
+ int dry_run)
788
{
789
if (add_submodule_odb(path))
790
return 1;
@@ -793,6 +795,12 @@ static int push_submodule(const char *path, int dry_run)
795
if (dry_run)
796
argv_array_push(&cp.args, "--dry-run");
797
798
+ if (push_options && push_options->nr) {
799
+ const struct string_list_item *item;
800
+ for_each_string_list_item(item, push_options)
801
+ argv_array_pushf(&cp.args, "--push-option=%s",
802
+ item->string);
803
+ }
804
prepare_submodule_repo_env(&cp.env_array);
805
cp.git_cmd = 1;
806
cp.no_stdin = 1;
@@ -807,6 +815,7 @@ static int push_submodule(const char *path, int dry_run)
815
816
int push_unpushed_submodules(struct sha1_array *commits,
817
const char *remotes_name,
818
+ const struct string_list *push_options,
819
int dry_run)
820
{
821
int i, ret = 1;
@@ -818,7 +827,7 @@ int push_unpushed_submodules(struct sha1_array *commits,
827
for (i = 0; i < needs_pushing.nr; i++) {
828
const char *path = needs_pushing.items[i].string;
829
fprintf(stderr, "Pushing submodule '%s'\n", path);
821
- if (!push_submodule(path, dry_run)) {
830
+ if (!push_submodule(path, push_options, dry_run)) {
831
fprintf(stderr, "Unable to push submodule '%s'\n", path);
832
ret = 0;
833
}
submodule.h
+1
@@ -92,6 +92,7 @@ extern int find_unpushed_submodules(struct sha1_array *commits,
92
struct string_list *needs_pushing);
93
extern int push_unpushed_submodules(struct sha1_array *commits,
94
const char *remotes_name,
95
+ const struct string_list *push_options,
96
int dry_run);
97
extern void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
98
extern int parallel_submodules(void);
t/t5545-push-options.sh
+40
@@ -142,6 +142,46 @@ test_expect_success 'push options work properly across http' '
142
test_cmp expect actual
143
'
144
145
+test_expect_success 'push options and submodules' '
146
+ test_when_finished "rm -rf parent" &&
147
+ test_when_finished "rm -rf parent_upstream" &&
148
+ mk_repo_pair &&
149
+ git -C upstream config receive.advertisePushOptions true &&
150
+ cp -r upstream parent_upstream &&
151
+ test_commit -C upstream one &&
152
+
153
+ test_create_repo parent &&
154
+ git -C parent remote add up ../parent_upstream &&
155
+ test_commit -C parent one &&
156
+ git -C parent push --mirror up &&
157
+
158
+ git -C parent submodule add ../upstream workbench &&
159
+ git -C parent/workbench remote add up ../../upstream &&
160
+ git -C parent commit -m "add submoule" &&
161
+
162
+ test_commit -C parent/workbench two &&
163
+ git -C parent add workbench &&
164
+ git -C parent commit -m "update workbench" &&
165
+
166
+ git -C parent push \
167
+ --push-option=asdf --push-option="more structured text" \
168
+ --recurse-submodules=on-demand up master &&
169
+
170
+ git -C upstream rev-parse --verify master >expect &&
171
+ git -C parent/workbench rev-parse --verify master >actual &&
172
+ test_cmp expect actual &&
173
+
174
+ git -C parent_upstream rev-parse --verify master >expect &&
175
+ git -C parent rev-parse --verify master >actual &&
176
+ test_cmp expect actual &&
177
+
178
+ printf "asdf\nmore structured text\n" >expect &&
179
+ test_cmp expect upstream/.git/hooks/pre-receive.push_options &&
180
+ test_cmp expect upstream/.git/hooks/post-receive.push_options &&
181
+ test_cmp expect parent_upstream/.git/hooks/pre-receive.push_options &&
182
+ test_cmp expect parent_upstream/.git/hooks/post-receive.push_options
183
+'
184
+
185
stop_httpd
186
187
test_done
transport.c
+1
@@ -1031,6 +1031,7 @@ int transport_push(struct transport *transport,
1031
1032
if (!push_unpushed_submodules(&commits,
1033
transport->remote->name,
1034
+ transport->push_options,
1035
pretend)) {
1036
sha1_array_clear(&commits);
1037
die("Failed to push all needed submodules!");