summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-09-14 14:03:36 -0400
committerDrew DeVault <sir@cmpwn.com>2019-10-22 10:23:24 -0400
commit02af1fcb69b91b3532b8b253ec82cdfce17ef28d (patch)
tree00474513405140855a4f78a5fb7fceed4d8e8907 /src
parentb246bed5ab83035d8aef95f1b7ff10dd746db7cb (diff)
downloadlibgit2-02af1fcb69b91b3532b8b253ec82cdfce17ef28d.tar.gz
apply: add GIT_APPLY_CHECK
This adds an option which will check if a diff is applicable without actually applying it; equivalent to git apply --check.
Diffstat (limited to 'src')
-rw-r--r--src/apply.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/apply.c b/src/apply.c
index 04242621a..65b057c60 100644
--- a/src/apply.c
+++ b/src/apply.c
@@ -845,13 +845,17 @@ int git_apply(
(error = git_reader_for_index(&post_reader, repo, postimage)) < 0)
goto done;
- if ((error = git_repository_index(&index, repo)) < 0 ||
- (error = git_indexwriter_init(&indexwriter, index)) < 0)
- goto done;
+ if (!(opts.flags & GIT_APPLY_CHECK))
+ if ((error = git_repository_index(&index, repo)) < 0 ||
+ (error = git_indexwriter_init(&indexwriter, index)) < 0)
+ goto done;
if ((error = apply_deltas(repo, pre_reader, preimage, post_reader, postimage, diff, &opts)) < 0)
goto done;
+ if ((opts.flags & GIT_APPLY_CHECK))
+ goto done;
+
switch (location) {
case GIT_APPLY_LOCATION_BOTH:
error = git_apply__to_workdir(repo, diff, preimage, postimage, location, &opts);