remote: add a creation flag for ignoring url.insteadOf
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
diff --git a/include/git2/remote.h b/include/git2/remote.h
index b39d081..7962f07 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -42,6 +42,14 @@ GIT_EXTERN(int) git_remote_create(
const char *url);
/**
+ * Remote creation options flags
+ */
+typedef enum {
+ /** Ignore the repository apply.insteadOf configuration */
+ GIT_REMOTE_CREATE_SKIP_INSTEADOF = (1 << 0),
+} git_remote_create_flags;
+
+/**
* Remote creation options structure
*
* Initialize with `GIT_REMOTE_CREATE_OPTIONS_INIT`. Alternatively, you can
@@ -65,6 +73,9 @@ typedef struct git_remote_create_options {
/** The fetchspec the remote should use. */
const char *fetchspec;
+
+ /** Additional flags for the remote. See git_remote_create_flags. */
+ unsigned int flags;
} git_remote_create_options;
#define GIT_REMOTE_CREATE_OPTIONS_VERSION 1
diff --git a/src/remote.c b/src/remote.c
index 1fa7b42..9dcd2fe 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -264,7 +264,7 @@ static int create_internal(git_remote **out, const char *url, const git_remote_c
(error = canonicalize_url(&canonical_url, url)) < 0)
goto on_error;
- if (opts->repository) {
+ if (opts->repository && !(opts->flags & GIT_REMOTE_CREATE_SKIP_INSTEADOF)) {
remote->url = apply_insteadof(config_ro, canonical_url.ptr, GIT_DIRECTION_FETCH);
} else {
remote->url = git__strdup(canonical_url.ptr);
diff --git a/tests/remote/create.c b/tests/remote/create.c
index cbc6096..9c51ed6 100644
--- a/tests/remote/create.c
+++ b/tests/remote/create.c
@@ -311,6 +311,23 @@ void test_remote_create__with_opts_detached(void)
git_remote_free(remote);
}
+
+void test_remote_create__with_opts_insteadof_disabled(void)
+{
+ git_remote *remote;
+ git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT;
+
+ opts.repository = _repo;
+ opts.flags = GIT_REMOTE_CREATE_SKIP_INSTEADOF;
+
+ cl_git_pass(git_remote_create_with_opts(&remote, "http://example.com/libgit2/libgit2", &opts));
+
+ cl_assert_equal_s(git_remote_url(remote), "http://example.com/libgit2/libgit2");
+ cl_assert_equal_p(git_remote_pushurl(remote), NULL);
+
+ git_remote_free(remote);
+}
+
static int create_with_name(git_remote **remote, git_repository *repo, const char *name, const char *url)
{
git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT;