fix remote/insteadof tests
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 92 93 94 95 96 97 98 99 100
diff --git a/src/remote.c b/src/remote.c
index bde4ce7..32973f7 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -30,7 +30,7 @@
static int dwim_refspecs(git_vector *out, git_vector *refspecs, git_vector *refs);
static int lookup_remote_prune_config(git_remote *remote, git_config *config, const char *name);
-char *apply_insteadof(git_config *config, const char *url, int direction);
+char *apply_insteadof(git_config *config, const char *url, int direction, int *matched);
static int add_refspec_to(git_vector *vector, const char *string, bool is_fetch)
{
@@ -210,7 +210,9 @@ int git_remote_create_with_opts(git_remote **out, const char *url, const git_rem
git_str var = GIT_STR_INIT;
git_str specbuf = GIT_STR_INIT;
const git_remote_create_options dummy_opts = GIT_REMOTE_CREATE_OPTIONS_INIT;
+ char *tmp;
int error = -1;
+ int matched;
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(url);
@@ -245,7 +247,12 @@ int git_remote_create_with_opts(git_remote **out, const char *url, const git_rem
goto on_error;
if (opts->repository && !(opts->flags & GIT_REMOTE_CREATE_SKIP_INSTEADOF)) {
- remote->url = apply_insteadof(config_ro, canonical_url.ptr, GIT_DIRECTION_FETCH);
+ remote->url = apply_insteadof(config_ro, canonical_url.ptr, GIT_DIRECTION_FETCH, &matched);
+ tmp = apply_insteadof(config_ro, canonical_url.ptr, GIT_DIRECTION_PUSH, &matched);
+ if (matched) {
+ remote->pushurl = tmp;
+ GIT_ERROR_CHECK_ALLOC(remote->pushurl);
+ }
} else {
remote->url = git__strdup(canonical_url.ptr);
}
@@ -457,7 +464,9 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
git_remote *remote = NULL;
git_str buf = GIT_STR_INIT;
const char *val;
+ char *tmp;
int error = 0;
+ int matched;
git_config *config;
struct refspec_cb_data data = { NULL };
bool optional_setting_found = false, found;
@@ -498,8 +507,13 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
remote->download_tags = GIT_REMOTE_DOWNLOAD_TAGS_AUTO;
if (found && strlen(val) > 0) {
- remote->url = apply_insteadof(config, val, GIT_DIRECTION_FETCH);
+ remote->url = apply_insteadof(config, val, GIT_DIRECTION_FETCH, &matched);
GIT_ERROR_CHECK_ALLOC(remote->url);
+ tmp = apply_insteadof(config, val, GIT_DIRECTION_PUSH, &matched);
+ if (matched) {
+ remote->pushurl = tmp;
+ GIT_ERROR_CHECK_ALLOC(remote->pushurl);
+ }
}
val = NULL;
@@ -518,7 +532,10 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
}
if (found && strlen(val) > 0) {
- remote->pushurl = apply_insteadof(config, val, GIT_DIRECTION_PUSH);
+ if (remote->pushurl) {
+ git__free(remote->pushurl);
+ }
+ remote->pushurl = apply_insteadof(config, val, GIT_DIRECTION_FETCH, &matched);
GIT_ERROR_CHECK_ALLOC(remote->pushurl);
}
@@ -2719,7 +2736,7 @@ int git_remote_push(git_remote *remote, const git_strarray *refspecs, const git_
#define SUFFIX_FETCH "insteadof"
#define SUFFIX_PUSH "pushinsteadof"
-char *apply_insteadof(git_config *config, const char *url, int direction)
+char *apply_insteadof(git_config *config, const char *url, int direction, int *matched)
{
size_t match_length, prefix_length, suffix_length;
char *replacement = NULL;
@@ -2732,6 +2749,8 @@ char *apply_insteadof(git_config *config, const char *url, int direction)
GIT_ASSERT_ARG_WITH_RETVAL(config, NULL);
GIT_ASSERT_ARG_WITH_RETVAL(url, NULL);
GIT_ASSERT_ARG_WITH_RETVAL(direction == GIT_DIRECTION_FETCH || direction == GIT_DIRECTION_PUSH, NULL);
+ GIT_ASSERT_ARG_WITH_RETVAL(matched, NULL);
+ *matched = 0;
/* Add 1 to prefix/suffix length due to the additional escaped dot */
prefix_length = strlen(PREFIX) + 1;
@@ -2777,6 +2796,7 @@ char *apply_insteadof(git_config *config, const char *url, int direction)
git__free(replacement);
+ *matched = 1;
return result.ptr;
}