1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.api;
11
12 import java.io.File;
13 import java.io.InputStream;
14 import org.eclipse.jgit.api.errors.GitAPIException;
15 import org.eclipse.jgit.internal.JGitText;
16 import org.eclipse.jgit.lib.Repository;
17 import org.eclipse.jgit.patch.PatchApplier;
18 import org.eclipse.jgit.patch.PatchApplier.Result;
19
20
21
22
23
24
25
26
27 public class ApplyCommand extends GitCommand<ApplyResult> {
28
29 private InputStream in;
30
31
32
33
34
35
36 ApplyCommand(Repository local) {
37 super(local);
38 if (local == null) {
39 throw new NullPointerException(JGitText.get().repositoryIsRequired);
40 }
41 }
42
43
44
45
46
47
48
49
50 public ApplyCommand setPatch(InputStream in) {
51 checkCallable();
52 this.in = in;
53 return this;
54 }
55
56
57
58
59
60
61
62
63
64
65
66 @Override
67 public ApplyResult call() throws GitAPIException {
68 checkCallable();
69 setCallable(false);
70 ApplyResult r = new ApplyResult();
71 PatchApplier patchApplier = new PatchApplier(repo);
72 Result applyResult = patchApplier.applyPatch(in);
73 for (String p : applyResult.getPaths()) {
74 r.addUpdatedFile(new File(repo.getWorkTree(), p));
75 }
76 return r;
77 }
78 }