validate non-optional settings in send {} and fetch {} config blocks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
diff --git a/libexec/got-read-gotconfig/got-read-gotconfig.c b/libexec/got-read-gotconfig/got-read-gotconfig.c
index 682d443..d2b3b15 100644
--- a/libexec/got-read-gotconfig/got-read-gotconfig.c
+++ b/libexec/got-read-gotconfig/got-read-gotconfig.c
@@ -230,8 +230,25 @@ send_gotconfig_remotes(struct imsgbuf *ibuf,
}
static const struct got_error *
+validate_protocol(const char *protocol, const char *repo_name)
+{
+ static char msg[512];
+
+ if (strcmp(protocol, "ssh") != 0 &&
+ strcmp(protocol, "git+ssh") != 0 &&
+ strcmp(protocol, "git") != 0) {
+ snprintf(msg, sizeof(msg),"unknown protocol \"%s\" "
+ "for remote repository \"%s\"", protocol, repo_name);
+ return got_error_msg(GOT_ERR_PARSE_CONFIG, msg);
+ }
+
+ return NULL;
+}
+
+static const struct got_error *
validate_config(struct gotconfig *gotconfig)
{
+ const struct got_error *err;
struct gotconfig_remote_repo *repo, *repo2;
static char msg[512];
@@ -251,29 +268,51 @@ validate_config(struct gotconfig *gotconfig)
return got_error_msg(GOT_ERR_PARSE_CONFIG, msg);
}
- if (repo->server == NULL) {
+ if (repo->server == NULL &&
+ (repo->fetch_config == NULL ||
+ repo->fetch_config->server == NULL) &&
+ (repo->send_config == NULL ||
+ repo->send_config->server == NULL)) {
snprintf(msg, sizeof(msg),
"server required for remote repository \"%s\"",
repo->name);
return got_error_msg(GOT_ERR_PARSE_CONFIG, msg);
}
- if (repo->protocol == NULL) {
+ if (repo->protocol == NULL &&
+ (repo->fetch_config == NULL ||
+ repo->fetch_config->protocol == NULL) &&
+ (repo->send_config == NULL ||
+ repo->send_config->protocol == NULL)) {
snprintf(msg, sizeof(msg),
"protocol required for remote repository \"%s\"",
repo->name);
return got_error_msg(GOT_ERR_PARSE_CONFIG, msg);
}
- if (strcmp(repo->protocol, "ssh") != 0 &&
- strcmp(repo->protocol, "git+ssh") != 0 &&
- strcmp(repo->protocol, "git") != 0) {
- snprintf(msg, sizeof(msg),"unknown protocol \"%s\" "
- "for remote repository \"%s\"", repo->protocol,
+
+ if (repo->protocol) {
+ err = validate_protocol(repo->protocol, repo->name);
+ if (err)
+ return err;
+ }
+ if (repo->fetch_config && repo->fetch_config->protocol) {
+ err = validate_protocol(repo->fetch_config->protocol,
repo->name);
- return got_error_msg(GOT_ERR_PARSE_CONFIG, msg);
+ if (err)
+ return err;
+ }
+ if (repo->send_config && repo->send_config->protocol) {
+ err = validate_protocol(repo->send_config->protocol,
+ repo->name);
+ if (err)
+ return err;
}
- if (repo->repository == NULL) {
+ if (repo->repository == NULL &&
+ (repo->fetch_config == NULL ||
+ repo->fetch_config->repository == NULL) &&
+ (repo->send_config == NULL ||
+ repo->send_config->repository == NULL)) {
snprintf(msg, sizeof(msg),
"repository path required for remote "
"repository \"%s\"", repo->name);