submodule--helper: add push-check subcommand
Add the 'push-check' subcommand to submodule--helper which is used to check if the provided remote and refspec can be used as part of a push operation in the submodule. 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
93481a6b89be41086997ecaf9454f0c0bf6a961e
1 file changed
+45
builtin/submodule--helper.c
+45
@@ -1105,6 +1105,50 @@ static int resolve_remote_submodule_branch(int argc, const char **argv,
1105
return 0;
1106
}
1107
1108
+static int push_check(int argc, const char **argv, const char *prefix)
1109
+{
1110
+ struct remote *remote;
1111
+
1112
+ if (argc < 2)
1113
+ die("submodule--helper push-check requires at least 1 argument");
1114
+
1115
+ /*
1116
+ * The remote must be configured.
1117
+ * This is to avoid pushing to the exact same URL as the parent.
1118
+ */
1119
+ remote = pushremote_get(argv[1]);
1120
+ if (!remote || remote->origin == REMOTE_UNCONFIGURED)
1121
+ die("remote '%s' not configured", argv[1]);
1122
+
1123
+ /* Check the refspec */
1124
+ if (argc > 2) {
1125
+ int i, refspec_nr = argc - 2;
1126
+ struct ref *local_refs = get_local_heads();
1127
+ struct refspec *refspec = parse_push_refspec(refspec_nr,
1128
+ argv + 2);
1129
+
1130
+ for (i = 0; i < refspec_nr; i++) {
1131
+ struct refspec *rs = refspec + i;
1132
+
1133
+ if (rs->pattern || rs->matching)
1134
+ continue;
1135
+
1136
+ /*
1137
+ * LHS must match a single ref
1138
+ * NEEDSWORK: add logic to special case 'HEAD' once
1139
+ * working with submodules in a detached head state
1140
+ * ceases to be the norm.
1141
+ */
1142
+ if (count_refspec_match(rs->src, local_refs, NULL) != 1)
1143
+ die("src refspec '%s' must name a ref",
1144
+ rs->src);
1145
+ }
1146
+ free_refspec(refspec_nr, refspec);
1147
+ }
1148
+
1149
+ return 0;
1150
+}
1151
+
1152
static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
1153
{
1154
int i;
@@ -1170,6 +1214,7 @@ static struct cmd_struct commands[] = {
1214
{"resolve-relative-url-test", resolve_relative_url_test, 0},
1215
{"init", module_init, SUPPORT_SUPER_PREFIX},
1216
{"remote-branch", resolve_remote_submodule_branch, 0},
1217
+ {"push-check", push_check, 0},
1218
{"absorb-git-dirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
1219
{"is-active", is_active, 0},
1220
};