refspec: expose the force update specifier through git_refspec_force() accessor
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
diff --git a/include/git2/refspec.h b/include/git2/refspec.h
index c0a8eab..1100e90 100644
--- a/include/git2/refspec.h
+++ b/include/git2/refspec.h
@@ -36,6 +36,14 @@ GIT_EXTERN(const char *) git_refspec_src(const git_refspec *refspec);
GIT_EXTERN(const char *) git_refspec_dst(const git_refspec *refspec);
/**
+ * Get the force update setting
+ *
+ * @param refspec the refspec
+ * @return 1 if force update has been set, 0 otherwise
+ */
+GIT_EXTERN(int) git_refspec_force(const git_refspec *refspec);
+
+/**
* Check if a refspec's source descriptor matches a reference
*
* @param refspec the refspec
diff --git a/src/refspec.c b/src/refspec.c
index 697b1bf..b6b1158 100644
--- a/src/refspec.c
+++ b/src/refspec.c
@@ -53,6 +53,13 @@ const char *git_refspec_dst(const git_refspec *refspec)
return refspec == NULL ? NULL : refspec->dst;
}
+int git_refspec_force(const git_refspec *refspec)
+{
+ assert(refspec);
+
+ return refspec->force;
+}
+
int git_refspec_src_matches(const git_refspec *refspec, const char *refname)
{
if (refspec == NULL || refspec->src == NULL)
diff --git a/src/remote.c b/src/remote.c
index 9740344..deb7350 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -189,6 +189,8 @@ int git_remote_save(const git_remote *remote)
git_buf_clear(&buf);
git_buf_clear(&value);
git_buf_printf(&buf, "remote.%s.fetch", remote->name);
+ if (remote->fetch.force)
+ git_buf_putc(&value, '+');
git_buf_printf(&value, "%s:%s", remote->fetch.src, remote->fetch.dst);
if (git_buf_oom(&buf) || git_buf_oom(&value))
return -1;
@@ -201,6 +203,8 @@ int git_remote_save(const git_remote *remote)
git_buf_clear(&buf);
git_buf_clear(&value);
git_buf_printf(&buf, "remote.%s.push", remote->name);
+ if (remote->push.force)
+ git_buf_putc(&value, '+');
git_buf_printf(&value, "%s:%s", remote->push.src, remote->push.dst);
if (git_buf_oom(&buf) || git_buf_oom(&value))
return -1;
diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remotes.c
index 0649c86..b3a0265 100644
--- a/tests-clar/network/remotes.c
+++ b/tests-clar/network/remotes.c
@@ -92,6 +92,7 @@ void test_network_remotes__save(void)
cl_assert(_refspec != NULL);
cl_assert_equal_s(git_refspec_src(_refspec), "refs/heads/*");
cl_assert_equal_s(git_refspec_dst(_refspec), "refs/remotes/upstream/*");
+ cl_assert(git_refspec_force(_refspec) == 0);
_refspec = git_remote_pushspec(_remote);
cl_assert(_refspec != NULL);