|
31 | 31 | typedef void (*each_submodule_fn)(const struct cache_entry *list_item,
|
32 | 32 | void *cb_data);
|
33 | 33 |
|
34 |
| -static char *repo_get_default_remote(struct repository *repo) |
| 34 | +static int repo_get_default_remote(struct repository *repo, char **default_remote) |
35 | 35 | {
|
36 |
| - char *dest = NULL, *ret; |
| 36 | + char *dest = NULL; |
37 | 37 | struct strbuf sb = STRBUF_INIT;
|
38 | 38 | struct ref_store *store = get_main_ref_store(repo);
|
39 | 39 | const char *refname = refs_resolve_ref_unsafe(store, "HEAD", 0, NULL,
|
40 | 40 | NULL);
|
41 | 41 |
|
42 | 42 | if (!refname)
|
43 |
| - die(_("No such ref: %s"), "HEAD"); |
| 43 | + return die_message(_("No such ref: %s"), "HEAD"); |
44 | 44 |
|
45 | 45 | /* detached HEAD */
|
46 |
| - if (!strcmp(refname, "HEAD")) |
47 |
| - return xstrdup("origin"); |
| 46 | + if (!strcmp(refname, "HEAD")) { |
| 47 | + *default_remote = xstrdup("origin"); |
| 48 | + return 0; |
| 49 | + } |
48 | 50 |
|
49 | 51 | if (!skip_prefix(refname, "refs/heads/", &refname))
|
50 |
| - die(_("Expecting a full ref name, got %s"), refname); |
| 52 | + return die_message(_("Expecting a full ref name, got %s"), |
| 53 | + refname); |
51 | 54 |
|
52 | 55 | strbuf_addf(&sb, "branch.%s.remote", refname);
|
53 | 56 | if (repo_config_get_string(repo, sb.buf, &dest))
|
54 |
| - ret = xstrdup("origin"); |
| 57 | + *default_remote = xstrdup("origin"); |
55 | 58 | else
|
56 |
| - ret = dest; |
| 59 | + *default_remote = dest; |
57 | 60 |
|
58 | 61 | strbuf_release(&sb);
|
59 |
| - return ret; |
| 62 | + return 0; |
60 | 63 | }
|
61 | 64 |
|
62 |
| -static char *get_default_remote_submodule(const char *module_path) |
| 65 | +static int get_default_remote_submodule(const char *module_path, char **default_remote) |
63 | 66 | {
|
64 | 67 | struct repository subrepo;
|
65 | 68 |
|
66 | 69 | if (repo_submodule_init(&subrepo, the_repository, module_path,
|
67 | 70 | null_oid()) < 0)
|
68 |
| - die(_("could not get a repository handle for submodule '%s'"), |
69 |
| - module_path); |
70 |
| - return repo_get_default_remote(&subrepo); |
| 71 | + return die_message(_("could not get a repository handle for submodule '%s'"), |
| 72 | + module_path); |
| 73 | + return repo_get_default_remote(&subrepo, default_remote); |
71 | 74 | }
|
72 | 75 |
|
73 | 76 | static char *get_default_remote(void)
|
74 | 77 | {
|
75 |
| - return repo_get_default_remote(the_repository); |
| 78 | + char *default_remote; |
| 79 | + int code = repo_get_default_remote(the_repository, &default_remote); |
| 80 | + |
| 81 | + if (code) |
| 82 | + exit(code); |
| 83 | + |
| 84 | + return default_remote; |
76 | 85 | }
|
77 | 86 |
|
78 | 87 | static char *resolve_relative_url(const char *rel_url, const char *up_path, int quiet)
|
@@ -1156,6 +1165,7 @@ static void sync_submodule(const char *path, const char *prefix,
|
1156 | 1165 | char *sub_origin_url, *super_config_url, *displaypath, *default_remote;
|
1157 | 1166 | struct strbuf sb = STRBUF_INIT;
|
1158 | 1167 | char *sub_config_path = NULL;
|
| 1168 | + int code; |
1159 | 1169 |
|
1160 | 1170 | if (!is_submodule_active(the_repository, path))
|
1161 | 1171 | return;
|
@@ -1195,10 +1205,9 @@ static void sync_submodule(const char *path, const char *prefix,
|
1195 | 1205 | goto cleanup;
|
1196 | 1206 |
|
1197 | 1207 | strbuf_reset(&sb);
|
1198 |
| - default_remote = get_default_remote_submodule(path); |
1199 |
| - if (!default_remote) |
1200 |
| - die(_("failed to get the default remote for submodule '%s'"), |
1201 |
| - path); |
| 1208 | + code = get_default_remote_submodule(path, &default_remote); |
| 1209 | + if (code) |
| 1210 | + exit(code); |
1202 | 1211 |
|
1203 | 1212 | remote_key = xstrfmt("remote.%s.url", default_remote);
|
1204 | 1213 | free(default_remote);
|
@@ -2419,9 +2428,16 @@ static int update_submodule(struct update_data *update_data)
|
2419 | 2428 | update_data->displaypath);
|
2420 | 2429 |
|
2421 | 2430 | if (update_data->remote) {
|
2422 |
| - char *remote_name = get_default_remote_submodule(update_data->sm_path); |
2423 |
| - const char *branch = remote_submodule_branch(update_data->sm_path); |
2424 |
| - char *remote_ref = xstrfmt("refs/remotes/%s/%s", remote_name, branch); |
| 2431 | + char *remote_name; |
| 2432 | + const char *branch; |
| 2433 | + char *remote_ref; |
| 2434 | + int code; |
| 2435 | + |
| 2436 | + code = get_default_remote_submodule(update_data->sm_path, &remote_name); |
| 2437 | + if (code) |
| 2438 | + return code; |
| 2439 | + branch = remote_submodule_branch(update_data->sm_path); |
| 2440 | + remote_ref = xstrfmt("refs/remotes/%s/%s", remote_name, branch); |
2425 | 2441 |
|
2426 | 2442 | if (!update_data->nofetch) {
|
2427 | 2443 | if (fetch_in_submodule(update_data->sm_path, update_data->depth,
|
|
0 commit comments