Clone: replace fetch spec with custom value
diff --git a/src/clone.c b/src/clone.c
index 8f10ca8..0665576 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -323,9 +323,11 @@ static int create_and_configure_origin(
(error = git_remote_set_callbacks(origin, options->remote_callbacks)) < 0)
goto on_error;
- if (options->fetch_spec &&
- (error = git_remote_add_fetch(origin, options->fetch_spec)) < 0)
- goto on_error;
+ if (options->fetch_spec) {
+ git_remote_clear_refspecs(origin);
+ if ((error = git_remote_add_fetch(origin, options->fetch_spec)) < 0)
+ goto on_error;
+ }
if (options->push_spec &&
(error = git_remote_add_push(origin, options->push_spec)) < 0)
diff --git a/tests-clar/clone/nonetwork.c b/tests-clar/clone/nonetwork.c
index 5066737..02066e0 100644
--- a/tests-clar/clone/nonetwork.c
+++ b/tests-clar/clone/nonetwork.c
@@ -149,7 +149,7 @@ void test_clone_nonetwork__custom_fetch_spec(void)
cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
cl_git_pass(git_remote_load(&g_remote, g_repo, "origin"));
- actual_fs = git_vector_get(&g_remote->refspecs, g_remote->refspecs.length - 1);
+ actual_fs = git_vector_get(&g_remote->refspecs, 0);
cl_assert_equal_s("refs/heads/master", git_refspec_src(actual_fs));
cl_assert_equal_s("refs/heads/foo", git_refspec_dst(actual_fs));