remote: add prune option to fetch Add a prune setting in the fetch options to allow to fall back to the configuration (the default) or to set it on or off.
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
diff --git a/include/git2/remote.h b/include/git2/remote.h
index 19b2fdf..41cf851 100644
--- a/include/git2/remote.h
+++ b/include/git2/remote.h
@@ -505,6 +505,21 @@ GIT_EXTERN(int) git_remote_init_callbacks(
git_remote_callbacks *opts,
unsigned int version);
+typedef enum {
+ /**
+ * Use the setting from the configuration
+ */
+ GIT_FETCH_PRUNE_FALLBACK,
+ /**
+ * Force pruning on
+ */
+ GIT_FETCH_PRUNE,
+ /**
+ * Force pruning off
+ */
+ GIT_FETCH_NO_PRUNE,
+} git_fetch_prune_t;
+
typedef struct {
int version;
@@ -512,6 +527,11 @@ typedef struct {
* Callbacks to use for this fetch operation
*/
git_remote_callbacks callbacks;
+
+ /**
+ * Whether to perform a prune after the fetch
+ */
+ git_fetch_prune_t prune;
} git_fetch_options;
#define GIT_FETCH_OPTIONS_VERSION 1
diff --git a/src/remote.c b/src/remote.c
index 9c044f7..a29b8aa 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -973,6 +973,7 @@ int git_remote_fetch(
const char *reflog_message)
{
int error;
+ bool prune = false;
git_buf reflog_msg_buf = GIT_BUF_INIT;
const git_remote_callbacks *cbs = NULL;
@@ -1008,7 +1009,16 @@ int git_remote_fetch(
if (error < 0)
return error;
- if (remote->prune_refs)
+ if (opts && opts->prune == GIT_FETCH_PRUNE)
+ prune = true;
+ else if (opts && opts->prune == GIT_FETCH_PRUNE_FALLBACK && remote->prune_refs)
+ prune = true;
+ else if (opts && opts->prune == GIT_FETCH_NO_PRUNE)
+ prune = false;
+ else
+ prune = remote->prune_refs;
+
+ if (prune)
error = git_remote_prune(remote, cbs);
return error;