Skip to content

Commit fdb116b

Browse files
committed
remote: add a creation flag for ignoring url.insteadOf
1 parent 3cbaebd commit fdb116b

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

include/git2/remote.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ GIT_EXTERN(int) git_remote_create(
4141
const char *name,
4242
const char *url);
4343

44+
/**
45+
* Remote creation options flags
46+
*/
47+
typedef enum {
48+
/** Ignore the repository apply.insteadOf configuration */
49+
GIT_REMOTE_CREATE_SKIP_INSTEADOF = (1 << 0),
50+
} git_remote_create_flags;
51+
4452
/**
4553
* Remote creation options structure
4654
*
@@ -65,6 +73,9 @@ typedef struct git_remote_create_options {
6573

6674
/** The fetchspec the remote should use. */
6775
const char *fetchspec;
76+
77+
/** Additional flags for the remote. See git_remote_create_flags. */
78+
unsigned int flags;
6879
} git_remote_create_options;
6980

7081
#define GIT_REMOTE_CREATE_OPTIONS_VERSION 1

src/remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ static int create_internal(git_remote **out, const char *url, const git_remote_c
264264
(error = canonicalize_url(&canonical_url, url)) < 0)
265265
goto on_error;
266266

267-
if (opts->repository) {
267+
if (opts->repository && !(opts->flags & GIT_REMOTE_CREATE_SKIP_INSTEADOF)) {
268268
remote->url = apply_insteadof(config_ro, canonical_url.ptr, GIT_DIRECTION_FETCH);
269269
} else {
270270
remote->url = git__strdup(canonical_url.ptr);

tests/remote/create.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,23 @@ void test_remote_create__with_opts_detached(void)
311311
git_remote_free(remote);
312312
}
313313

314+
315+
void test_remote_create__with_opts_insteadof_disabled(void)
316+
{
317+
git_remote *remote;
318+
git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT;
319+
320+
opts.repository = _repo;
321+
opts.flags = GIT_REMOTE_CREATE_SKIP_INSTEADOF;
322+
323+
cl_git_pass(git_remote_create_with_opts(&remote, "http://example.com/libgit2/libgit2", &opts));
324+
325+
cl_assert_equal_s(git_remote_url(remote), "http://example.com/libgit2/libgit2");
326+
cl_assert_equal_p(git_remote_pushurl(remote), NULL);
327+
328+
git_remote_free(remote);
329+
}
330+
314331
static int create_with_name(git_remote **remote, git_repository *repo, const char *name, const char *url)
315332
{
316333
git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT;

0 commit comments

Comments
 (0)