summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2018-03-19 19:50:45 +0000
committerEdward Thomson <ethomson@edwardthomson.com>2018-11-04 09:21:48 +0000
commitf83bbe0a882cb141c636ebf7657462b3be85dea8 (patch)
tree1b848c7bb1fc3fbe2b7baa3e2a67e7a35f4eb9e6 /include
parent664cda6f6b5a29b486b231d77c707ad54a2f58ce (diff)
downloadlibgit2-f83bbe0a882cb141c636ebf7657462b3be85dea8.tar.gz
apply: introduce `git_apply`
Introduce `git_apply`, which will take a `git_diff` and apply it to the working directory (akin to `git apply`), the index (akin to `git apply --cached`), or both (akin to `git apply --index`).
Diffstat (limited to 'include')
-rw-r--r--include/git2/apply.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/include/git2/apply.h b/include/git2/apply.h
index a4ec4fc08..3bf6aad63 100644
--- a/include/git2/apply.h
+++ b/include/git2/apply.h
@@ -36,6 +36,48 @@ GIT_EXTERN(int) git_apply_to_tree(
git_tree *preimage,
git_diff *diff);
+typedef enum {
+ /**
+ * Apply the patch to the workdir, leaving the index untouched.
+ * This is the equivalent of `git apply` with no location argument.
+ */
+ GIT_APPLY_LOCATION_WORKDIR = 0,
+
+ /**
+ * Apply the patch to the index, leaving the working directory
+ * untouched. This is the equivalent of `git apply --cached`.
+ */
+ GIT_APPLY_LOCATION_INDEX = 1,
+
+ /**
+ * Apply the patch to both the working directory and the index.
+ * This is the equivalent of `git apply --index`.
+ */
+ GIT_APPLY_LOCATION_BOTH = 2,
+} git_apply_location_t;
+
+typedef struct {
+ unsigned int version;
+
+ git_apply_location_t location;
+} git_apply_options;
+
+#define GIT_APPLY_OPTIONS_VERSION 1
+#define GIT_APPLY_OPTIONS_INIT {GIT_APPLY_OPTIONS_VERSION}
+
+/**
+ * Apply a `git_diff` to the given repository, making changes directly
+ * in the working directory, the index, or both.
+ *
+ * @param repo the repository to apply to
+ * @param diff the diff to apply
+ * @param options the options for the apply (or null for defaults)
+ */
+GIT_EXTERN(int) git_apply(
+ git_repository *repo,
+ git_diff *diff,
+ git_apply_options *options);
+
/** @} */
GIT_END_DECL
#endif