fetch: add a test for local fetching
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
diff --git a/src/remote.c b/src/remote.c
index b588864..baec1ed 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -1822,7 +1822,8 @@ static int update_one_tip(
if (error < 0 && error != GIT_ENOTFOUND)
goto done;
- if (!spec->force &&
+ if (!(error || error == GIT_ENOTFOUND) &&
+ !spec->force &&
!git_graph_descendant_of(remote->repo, &head->oid, &old)) {
error = 0;
goto done;
@@ -1856,6 +1857,7 @@ static int update_one_tip(
done:
git_reference_free(ref);
+ git_str_dispose(&refname);
return error;
}
diff --git a/tests/fetch/local.c b/tests/fetch/local.c
new file mode 100644
index 0000000..b4583b2
--- /dev/null
+++ b/tests/fetch/local.c
@@ -0,0 +1,36 @@
+#include "clar_libgit2.h"
+#include "futils.h"
+
+static git_repository *repo;
+
+void test_fetch_local__initialize(void)
+{
+ cl_git_pass(git_repository_init(&repo, "./fetch", 0));
+}
+
+void test_fetch_local__cleanup(void)
+{
+ git_repository_free(repo);
+ repo = NULL;
+
+ cl_fixture_cleanup("./fetch");
+}
+
+void test_fetch_local__defaults(void)
+{
+ git_remote *remote;
+ git_object *obj;
+ git_oid expected_id;
+
+ cl_git_pass(git_remote_create(&remote, repo, "test",
+ cl_fixture("testrepo.git")));
+ cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL));
+
+ git_oid_fromstr(&expected_id, "258f0e2a959a364e40ed6603d5d44fbb24765b10");
+
+ cl_git_pass(git_revparse_single(&obj, repo, "refs/remotes/test/haacked"));
+ cl_assert_equal_oid(&expected_id, git_object_id(obj));
+
+ git_object_free(obj);
+ git_remote_free(remote);
+}