
PullRequest: Remove code deprecated by 2293c37
This also drops pull_request.conflict_files column.
@4591610e690985d8f53494c12429ed4fc53f1606
--- app/actors/PullRequestActor.java
+++ app/actors/PullRequestActor.java
... | ... | @@ -52,14 +52,14 @@ |
52 | 52 |
if (!wasConflict && mergeResult.conflicts()) { |
53 | 53 |
mergeResult.setConflictStateOfPullRequest(); |
54 | 54 |
NotificationEvent notiEvent = NotificationEvent.afterMerge(message.getSender(), |
55 |
- pullRequest, mergeResult.getGitConflicts(), State.CONFLICT); |
|
55 |
+ pullRequest, State.CONFLICT); |
|
56 | 56 |
PullRequestEvent.addMergeEvent(notiEvent.getSender(), EventType.PULL_REQUEST_MERGED, State.CONFLICT, pullRequest); |
57 | 57 |
} |
58 | 58 |
|
59 |
- if (wasConflict && mergeResult.resolved()) { |
|
59 |
+ if (wasConflict && !mergeResult.conflicts()) { |
|
60 | 60 |
mergeResult.setResolvedStateOfPullRequest(); |
61 | 61 |
NotificationEvent notiEvent = NotificationEvent.afterMerge(message.getSender(), |
62 |
- pullRequest, mergeResult.getGitConflicts(), State.RESOLVED); |
|
62 |
+ pullRequest, State.RESOLVED); |
|
63 | 63 |
PullRequestEvent.addMergeEvent(notiEvent.getSender(), EventType.PULL_REQUEST_MERGED, State.RESOLVED, pullRequest); |
64 | 64 |
} |
65 | 65 |
|
--- app/models/CodeCommentThread.java
+++ app/models/CodeCommentThread.java
... | ... | @@ -22,19 +22,19 @@ |
22 | 22 |
|
23 | 23 |
import org.apache.commons.lang3.ObjectUtils; |
24 | 24 |
import org.apache.commons.lang3.StringUtils; |
25 |
- |
|
26 |
-import javax.annotation.Nullable; |
|
27 |
-import javax.persistence.*; |
|
28 |
-import java.util.ArrayList; |
|
29 |
-import java.util.List; |
|
30 |
- |
|
31 |
-import java.io.IOException; |
|
32 | 25 |
import org.eclipse.jgit.api.errors.GitAPIException; |
33 | 26 |
import org.eclipse.jgit.errors.MissingObjectException; |
34 | 27 |
import org.eclipse.jgit.lib.Repository; |
35 | 28 |
|
29 |
+import javax.annotation.Nullable; |
|
30 |
+import javax.persistence.*; |
|
31 |
+import java.io.IOException; |
|
32 |
+import java.util.ArrayList; |
|
33 |
+import java.util.List; |
|
34 |
+ |
|
36 | 35 |
import static models.CodeRange.Side; |
37 |
-import static models.CodeRange.Side.*; |
|
36 |
+import static models.CodeRange.Side.A; |
|
37 |
+import static models.CodeRange.Side.B; |
|
38 | 38 |
|
39 | 39 |
/** |
40 | 40 |
* @author Keesun Baik |
... | ... | @@ -102,20 +102,20 @@ |
102 | 102 |
path = path.substring(1); |
103 | 103 |
} |
104 | 104 |
|
105 |
- Repository mergedRepository = pullRequest.getMergedRepository(); |
|
105 |
+ Repository repository = pullRequest.getRepository(); |
|
106 | 106 |
|
107 | 107 |
try { |
108 | 108 |
if (StringUtils.isNotEmpty(prevCommitId)) { |
109 |
- _isOutdated = !PullRequest.noChangesBetween(mergedRepository, |
|
110 |
- pullRequest.mergedCommitIdFrom, mergedRepository, prevCommitId, path); |
|
109 |
+ _isOutdated = !PullRequest.noChangesBetween(repository, |
|
110 |
+ pullRequest.mergedCommitIdFrom, repository, prevCommitId, path); |
|
111 | 111 |
} |
112 | 112 |
|
113 | 113 |
if (_isOutdated) { |
114 | 114 |
return _isOutdated; |
115 | 115 |
} |
116 | 116 |
|
117 |
- _isOutdated = !PullRequest.noChangesBetween(mergedRepository, |
|
118 |
- pullRequest.mergedCommitIdTo, mergedRepository, commitId, path); |
|
117 |
+ _isOutdated = !PullRequest.noChangesBetween(repository, |
|
118 |
+ pullRequest.mergedCommitIdTo, repository, commitId, path); |
|
119 | 119 |
} catch (MissingObjectException e) { |
120 | 120 |
play.Logger.warn("Possible false positive of outdated detection because of missing git object: " + e.getMessage()); |
121 | 121 |
return true; |
--- app/models/NotificationEvent.java
+++ app/models/NotificationEvent.java
... | ... | @@ -30,7 +30,6 @@ |
30 | 30 |
import org.apache.commons.collections.Predicate; |
31 | 31 |
import org.apache.commons.lang3.StringUtils; |
32 | 32 |
import org.eclipse.jgit.api.errors.GitAPIException; |
33 |
-import org.eclipse.jgit.lib.Repository; |
|
34 | 33 |
import org.eclipse.jgit.revwalk.RevCommit; |
35 | 34 |
import org.joda.time.DateTime; |
36 | 35 |
import org.tmatesoft.svn.core.SVNException; |
... | ... | @@ -48,6 +47,7 @@ |
48 | 47 |
import javax.servlet.ServletException; |
49 | 48 |
import java.io.IOException; |
50 | 49 |
import java.io.UnsupportedEncodingException; |
50 |
+import java.net.URLEncoder; |
|
51 | 51 |
import java.util.Date; |
52 | 52 |
import java.util.HashSet; |
53 | 53 |
import java.util.List; |
... | ... | @@ -55,7 +55,6 @@ |
55 | 55 |
import java.util.concurrent.TimeUnit; |
56 | 56 |
import java.util.regex.Matcher; |
57 | 57 |
import java.util.regex.Pattern; |
58 |
-import java.net.URLEncoder; |
|
59 | 58 |
|
60 | 59 |
import static models.enumeration.EventType.*; |
61 | 60 |
|
... | ... | @@ -347,15 +346,12 @@ |
347 | 346 |
/** |
348 | 347 |
* @see {@link actors.PullRequestActor#processPullRequestMerging(models.PullRequestEventMessage, models.PullRequest)} |
349 | 348 |
*/ |
350 |
- public static NotificationEvent afterMerge(User sender, PullRequest pullRequest, GitConflicts conflicts, State state) { |
|
349 |
+ public static NotificationEvent afterMerge(User sender, PullRequest pullRequest, State state) { |
|
351 | 350 |
NotificationEvent notiEvent = createFrom(sender, pullRequest); |
352 | 351 |
notiEvent.title = formatReplyTitle(pullRequest); |
353 | 352 |
notiEvent.receivers = state == State.MERGED ? getReceiversWithRelatedAuthors(sender, pullRequest) : getReceivers(sender, pullRequest); |
354 | 353 |
notiEvent.eventType = PULL_REQUEST_MERGED; |
355 | 354 |
notiEvent.newValue = state.state(); |
356 |
- if (conflicts != null) { |
|
357 |
- notiEvent.oldValue = StringUtils.join(conflicts.conflictFiles, "\n"); |
|
358 |
- } |
|
359 | 355 |
NotificationEvent.add(notiEvent); |
360 | 356 |
return notiEvent; |
361 | 357 |
} |
... | ... | @@ -756,12 +752,10 @@ |
756 | 752 |
String failureMessage = |
757 | 753 |
"Failed to get authors related to the pullrequest " + pullRequest; |
758 | 754 |
try { |
759 |
- Repository clonedRepository = GitRepository.buildMergingRepository(pullRequest); |
|
760 |
- |
|
761 | 755 |
if (pullRequest.mergedCommitIdFrom != null |
762 | 756 |
&& pullRequest.mergedCommitIdTo != null) { |
763 | 757 |
receivers.addAll(GitRepository.getRelatedAuthors( |
764 |
- clonedRepository, |
|
758 |
+ new GitRepository(pullRequest.toProject).getRepository(), |
|
765 | 759 |
pullRequest.mergedCommitIdFrom, |
766 | 760 |
pullRequest.mergedCommitIdTo)); |
767 | 761 |
} |
--- app/models/PullRequest.java
+++ app/models/PullRequest.java
... | ... | @@ -63,7 +63,6 @@ |
63 | 63 |
import javax.persistence.*; |
64 | 64 |
import javax.persistence.OrderBy; |
65 | 65 |
import javax.validation.constraints.Size; |
66 |
-import java.io.File; |
|
67 | 66 |
import java.io.IOException; |
68 | 67 |
import java.text.MessageFormat; |
69 | 68 |
import java.util.*; |
... | ... | @@ -79,9 +78,6 @@ |
79 | 78 |
public static final Finder<Long, PullRequest> finder = new Finder<>(Long.class, PullRequest.class); |
80 | 79 |
|
81 | 80 |
public static final int ITEMS_PER_PAGE = 15; |
82 |
- |
|
83 |
- @Transient |
|
84 |
- public Repository mergedRepo = null; |
|
85 | 81 |
|
86 | 82 |
@Id |
87 | 83 |
public Long id; |
... | ... | @@ -146,8 +142,6 @@ |
146 | 142 |
public String mergedCommitIdTo; |
147 | 143 |
|
148 | 144 |
public Long number; |
149 |
- |
|
150 |
- public String conflictFiles; |
|
151 | 145 |
|
152 | 146 |
@ManyToMany(cascade = CascadeType.ALL) |
153 | 147 |
@JoinTable( |
... | ... | @@ -665,16 +659,6 @@ |
665 | 659 |
return repository; |
666 | 660 |
} |
667 | 661 |
|
668 |
- public Repository getMergedRepository() throws IOException { |
|
669 |
- if (mergedRepo == null) { |
|
670 |
- File dir = new File( |
|
671 |
- GitRepository.getDirectoryForMerging(toProject.owner, toProject.name) + "/.git"); |
|
672 |
- mergedRepo = new RepositoryBuilder().setGitDir(dir).build(); |
|
673 |
- } |
|
674 |
- |
|
675 |
- return mergedRepo; |
|
676 |
- } |
|
677 |
- |
|
678 | 662 |
@Transient |
679 | 663 |
public List<FileDiff> getDiff(String revA, String revB) throws IOException { |
680 | 664 |
Repository repository = getRepository(); |
... | ... | @@ -769,11 +753,6 @@ |
769 | 753 |
public void delete() { |
770 | 754 |
deleteIssueEvents(); |
771 | 755 |
super.delete(); |
772 |
- } |
|
773 |
- |
|
774 |
- @Transient |
|
775 |
- public String[] getConflictFiles() { |
|
776 |
- return StringUtils.split(this.conflictFiles, ","); |
|
777 | 756 |
} |
778 | 757 |
|
779 | 758 |
@Transient |
--- app/models/PullRequestMergeResult.java
+++ app/models/PullRequestMergeResult.java
... | ... | @@ -21,25 +21,16 @@ |
21 | 21 |
package models; |
22 | 22 |
|
23 | 23 |
import models.enumeration.State; |
24 |
-import org.apache.commons.lang3.StringUtils; |
|
25 | 24 |
import playRepository.GitCommit; |
26 |
-import playRepository.GitConflicts; |
|
27 | 25 |
|
28 | 26 |
import java.util.ArrayList; |
29 | 27 |
import java.util.List; |
30 | 28 |
|
31 | 29 |
public class PullRequestMergeResult { |
32 |
- private GitConflicts gitConflicts; |
|
33 | 30 |
private List<GitCommit> gitCommits; |
34 | 31 |
private List<PullRequestCommit> newCommits; |
35 | 32 |
private PullRequest pullRequest; |
36 | 33 |
|
37 |
- public GitConflicts getGitConflicts() { |
|
38 |
- return gitConflicts; |
|
39 |
- } |
|
40 |
- public void setGitConflicts(GitConflicts gitConflicts) { |
|
41 |
- this.gitConflicts = gitConflicts; |
|
42 |
- } |
|
43 | 34 |
public List<GitCommit> getGitCommits() { |
44 | 35 |
return gitCommits; |
45 | 36 |
} |
... | ... | @@ -55,20 +46,13 @@ |
55 | 46 |
public boolean hasDiffCommits() { |
56 | 47 |
return this.gitCommits.size() > 0; |
57 | 48 |
} |
58 |
- public boolean resolved() { |
|
59 |
- return this.gitConflicts == null && !pullRequest.isConflict; |
|
60 |
- } |
|
49 |
+ |
|
61 | 50 |
public boolean conflicts() { |
62 |
- return this.gitConflicts != null && pullRequest.isConflict; |
|
51 |
+ return pullRequest.isConflict; |
|
63 | 52 |
} |
53 |
+ |
|
64 | 54 |
public List<PullRequestCommit> getNewCommits() { |
65 | 55 |
return newCommits; |
66 |
- } |
|
67 |
- public String getConflictFilesToString() { |
|
68 |
- if (gitConflicts == null) { |
|
69 |
- return StringUtils.EMPTY; |
|
70 |
- } |
|
71 |
- return StringUtils.join(gitConflicts.conflictFiles, PullRequest.DELIMETER); |
|
72 | 56 |
} |
73 | 57 |
|
74 | 58 |
public List<PullRequestCommit> findNewCommits() { |
... | ... | @@ -136,17 +120,14 @@ |
136 | 120 |
|
137 | 121 |
public void setConflictStateOfPullRequest() { |
138 | 122 |
pullRequest.isConflict = true; |
139 |
- pullRequest.conflictFiles = StringUtils.EMPTY; |
|
140 | 123 |
} |
141 | 124 |
|
142 | 125 |
public void setResolvedStateOfPullRequest() { |
143 | 126 |
pullRequest.isConflict = false; |
144 |
- pullRequest.conflictFiles = StringUtils.EMPTY; |
|
145 | 127 |
} |
146 | 128 |
|
147 | 129 |
public void setMergedStateOfPullRequest(User receiver) { |
148 | 130 |
pullRequest.isConflict = false; |
149 |
- pullRequest.conflictFiles = StringUtils.EMPTY; |
|
150 | 131 |
pullRequest.state = State.MERGED; |
151 | 132 |
pullRequest.receiver = receiver; |
152 | 133 |
} |
--- app/playRepository/GitConflicts.java
... | ... | @@ -1,89 +0,0 @@ |
1 | -/** | |
2 | - * Yobi, Project Hosting SW | |
3 | - * | |
4 | - * Copyright 2013 NAVER Corp. | |
5 | - * http://yobi.io | |
6 | - * | |
7 | - * @Author Keesun Baik | |
8 | - * | |
9 | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
10 | - * you may not use this file except in compliance with the License. | |
11 | - * You may obtain a copy of the License at | |
12 | - * | |
13 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
14 | - * | |
15 | - * Unless required by applicable law or agreed to in writing, software | |
16 | - * distributed under the License is distributed on an "AS IS" BASIS, | |
17 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
18 | - * See the License for the specific language governing permissions and | |
19 | - * limitations under the License. | |
20 | - */ | |
21 | -package playRepository; | |
22 | - | |
23 | -import org.eclipse.jgit.api.MergeResult; | |
24 | -import org.eclipse.jgit.lib.ObjectId; | |
25 | -import org.eclipse.jgit.lib.Repository; | |
26 | -import org.eclipse.jgit.revwalk.RevWalk; | |
27 | - | |
28 | -import java.io.IOException; | |
29 | -import java.util.ArrayList; | |
30 | -import java.util.List; | |
31 | -import java.util.Map; | |
32 | - | |
33 | -public class GitConflicts { | |
34 | - | |
35 | - public List<String> conflictFiles = new ArrayList<>(); | |
36 | - | |
37 | - public List<Conflict> conflictDetails = new ArrayList<>(); | |
38 | - | |
39 | - /** | |
40 | - * @param repository | |
41 | - * @param mergeResult | |
42 | - * @see http://download.eclipse.org/jgit/docs/latest/apidocs/org/eclipse/jgit/api/MergeResult.html#getConflicts() | |
43 | - */ | |
44 | - public GitConflicts(Repository repository, MergeResult mergeResult) { | |
45 | - Map<String, int[][]> allConflicts = mergeResult.getConflicts(); | |
46 | - for (String path : allConflicts.keySet()) { | |
47 | - conflictFiles.add(path); | |
48 | - int[][] conflicts = allConflicts.get(path); | |
49 | - for (int[] c : conflicts) { | |
50 | - Conflict conflict = new Conflict(); | |
51 | - conflict.fileName = path; | |
52 | - for (int j = 0; j < (c.length) - 1; ++j) { | |
53 | - if (c[j] >= 0) { | |
54 | - ObjectId objectId = mergeResult.getMergedCommits()[j]; | |
55 | - RevWalk revWalk = new RevWalk(repository); | |
56 | - | |
57 | - CommitAndLine commitAndLine = new CommitAndLine(); | |
58 | - try { | |
59 | - commitAndLine.gitCommit = new GitCommit(revWalk.parseCommit(objectId)); | |
60 | - commitAndLine.lineNumber = c[j]; | |
61 | - conflict.commitAndLines.add(commitAndLine); | |
62 | - } catch (IOException e) { | |
63 | - throw new RuntimeException(e); | |
64 | - } | |
65 | - } | |
66 | - } | |
67 | - conflictDetails.add(conflict); | |
68 | - } | |
69 | - } | |
70 | - | |
71 | - } | |
72 | - | |
73 | - public static class Conflict { | |
74 | - | |
75 | - public String fileName; | |
76 | - | |
77 | - public List<CommitAndLine> commitAndLines = new ArrayList<>(); | |
78 | - | |
79 | - } | |
80 | - | |
81 | - public static class CommitAndLine { | |
82 | - | |
83 | - public GitCommit gitCommit; | |
84 | - | |
85 | - public int lineNumber; | |
86 | - | |
87 | - } | |
88 | - | |
89 | -} |
--- app/playRepository/GitRepository.java
+++ app/playRepository/GitRepository.java
... | ... | @@ -35,7 +35,8 @@ |
35 | 35 |
import org.apache.tika.metadata.Metadata; |
36 | 36 |
import org.codehaus.jackson.JsonNode; |
37 | 37 |
import org.codehaus.jackson.node.ObjectNode; |
38 |
-import org.eclipse.jgit.api.*; |
|
38 |
+import org.eclipse.jgit.api.Git; |
|
39 |
+import org.eclipse.jgit.api.LogCommand; |
|
39 | 40 |
import org.eclipse.jgit.api.errors.GitAPIException; |
40 | 41 |
import org.eclipse.jgit.blame.BlameResult; |
41 | 42 |
import org.eclipse.jgit.diff.*; |
... | ... | @@ -48,7 +49,6 @@ |
48 | 49 |
import org.eclipse.jgit.revwalk.RevTree; |
49 | 50 |
import org.eclipse.jgit.revwalk.RevWalk; |
50 | 51 |
import org.eclipse.jgit.storage.file.WindowCacheConfig; |
51 |
-import org.eclipse.jgit.transport.RefSpec; |
|
52 | 52 |
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; |
53 | 53 |
import org.eclipse.jgit.treewalk.AbstractTreeIterator; |
54 | 54 |
import org.eclipse.jgit.treewalk.CanonicalTreeParser; |
... | ... | @@ -102,10 +102,6 @@ |
102 | 102 |
|
103 | 103 |
public static String getRepoForMergingPrefix() { |
104 | 104 |
return repoForMergingPrefix; |
105 |
- } |
|
106 |
- |
|
107 |
- public static void setRepoForMergingPrefix(String repoForMergingPrefix) { |
|
108 |
- GitRepository.repoForMergingPrefix = repoForMergingPrefix; |
|
109 | 105 |
} |
110 | 106 |
|
111 | 107 |
private final Repository repository; |
... | ... | @@ -881,48 +877,6 @@ |
881 | 877 |
.call(); |
882 | 878 |
} |
883 | 879 |
|
884 |
- public static void deleteMergingDirectory(PullRequest pullRequest) { |
|
885 |
- Project toProject = pullRequest.toProject; |
|
886 |
- String directoryForMerging = GitRepository.getDirectoryForMerging(toProject.owner, toProject.name); |
|
887 |
- FileUtil.rm_rf(new File(directoryForMerging)); |
|
888 |
- } |
|
889 |
- |
|
890 |
- /** |
|
891 |
- * Pushes branches. |
|
892 |
- * |
|
893 |
- * @param repository the source repository |
|
894 |
- * @param remote the destination repository |
|
895 |
- * @param src src of refspec |
|
896 |
- * @param dest dst of refspec |
|
897 |
- * @throws GitAPIException |
|
898 |
- */ |
|
899 |
- public static void push(Repository repository, String remote, String src, String dest) throws GitAPIException { |
|
900 |
- new Git(repository).push() |
|
901 |
- .setRemote(remote) |
|
902 |
- .setRefSpecs(new RefSpec(src + ":" + dest)) |
|
903 |
- .call(); |
|
904 |
- } |
|
905 |
- |
|
906 |
- /** |
|
907 |
- * Merges a branch. |
|
908 |
- * |
|
909 |
- * Add --no-ff option to create a merge commit even when the merge resolves |
|
910 |
- * as a fast-forward. |
|
911 |
- * |
|
912 |
- * @param repository |
|
913 |
- * @param branchName the name of a branch to be merged. |
|
914 |
- * @return |
|
915 |
- * @throws GitAPIException |
|
916 |
- * @throws IOException |
|
917 |
- */ |
|
918 |
- public static MergeResult merge(Repository repository, String branchName) throws GitAPIException, IOException { |
|
919 |
- ObjectId branch = repository.resolve(branchName); |
|
920 |
- return new Git(repository).merge() |
|
921 |
- .setFastForward(MergeCommand.FastForwardMode.NO_FF) |
|
922 |
- .include(branch) |
|
923 |
- .call(); |
|
924 |
- } |
|
925 |
- |
|
926 | 880 |
/** |
927 | 881 |
* Checks out the branch. |
928 | 882 |
* |
... | ... | @@ -954,27 +908,17 @@ |
954 | 908 |
return getDirectoryForMerging(owner, projectName) + "/.git/objects"; |
955 | 909 |
} |
956 | 910 |
|
957 |
- public static List<RevCommit> diffRevCommits(Repository repository, String fromBranch, String toBranch) throws IOException, GitAPIException { |
|
958 |
- ObjectId from = repository.resolve(fromBranch); |
|
959 |
- ObjectId to = repository.resolve(toBranch); |
|
960 |
- return diffRevCommits(repository, from, to); |
|
961 |
- } |
|
962 |
- |
|
963 | 911 |
@SuppressWarnings("unchecked") |
964 | 912 |
public static List<RevCommit> diffRevCommits(Repository repository, ObjectId from, ObjectId to) throws IOException, GitAPIException { |
965 | 913 |
return IteratorUtils.toList( |
966 | 914 |
new Git(repository).log().addRange(from, to).call().iterator()); |
967 | 915 |
} |
968 | 916 |
|
969 |
- public static List<GitCommit> diffCommits(Repository repository, String fromBranch, String toBranch) throws IOException, GitAPIException { |
|
970 |
- return wrap(diffRevCommits(repository, fromBranch, toBranch)); |
|
971 |
- } |
|
972 |
- |
|
973 | 917 |
public static List<GitCommit> diffCommits(Repository repository, ObjectId from, ObjectId to) throws IOException, GitAPIException { |
974 |
- return wrap(diffRevCommits(repository, from, to)); |
|
918 |
+ return wrapInGitCommits(diffRevCommits(repository, from, to)); |
|
975 | 919 |
} |
976 | 920 |
|
977 |
- public static List<GitCommit> wrap(List<RevCommit> revCommits) throws IOException, GitAPIException { |
|
921 |
+ public static List<GitCommit> wrapInGitCommits(List<RevCommit> revCommits) throws IOException, GitAPIException { |
|
978 | 922 |
List<GitCommit> commits = new ArrayList<>(); |
979 | 923 |
for (RevCommit revCommit : revCommits) { |
980 | 924 |
commits.add(new GitCommit(revCommit)); |
... | ... | @@ -1166,98 +1110,6 @@ |
1166 | 1110 |
.setBranchNames(branchName) |
1167 | 1111 |
.setForce(true) |
1168 | 1112 |
.call(); |
1169 |
- } |
|
1170 |
- |
|
1171 |
- /** |
|
1172 |
- * Fetches branches. |
|
1173 |
- * |
|
1174 |
- * @param repository Stores fetched objects and refs in this repository. |
|
1175 |
- * @param project Fetches from this project. |
|
1176 |
- * @param fromBranch src of refspec |
|
1177 |
- * @param toBranch dst of refspec |
|
1178 |
- * @throws GitAPIException |
|
1179 |
- * @throws IOException |
|
1180 |
- * @see <a href="https://www.kernel.org/pub/software/scm/git/docs/git-fetch.html">git-fetch</a> |
|
1181 |
- */ |
|
1182 |
- public static void fetch(Repository repository, Project project, String fromBranch, String toBranch) throws GitAPIException, IOException { |
|
1183 |
- new Git(repository).fetch() |
|
1184 |
- .setRemote(GitRepository.getGitDirectoryURL(project)) |
|
1185 |
- .setRefSpecs(new RefSpec(fromBranch + ":" + toBranch)) |
|
1186 |
- .call(); |
|
1187 |
- } |
|
1188 |
- |
|
1189 |
- /** |
|
1190 |
- * @see models.PullRequest#attemptMerge() |
|
1191 |
- * @see models.PullRequest#merge(models.PullRequestEventMessage) |
|
1192 |
- */ |
|
1193 |
- public static void cloneAndFetch(PullRequest pullRequest, AfterCloneAndFetchOperation operation) { |
|
1194 |
- Repository cloneRepository = null; |
|
1195 |
- String mergingBranch = null; |
|
1196 |
- String destFromBranchName = null; |
|
1197 |
- try { |
|
1198 |
- synchronized (PROJECT_LOCK.get(pullRequest.toProject)) { |
|
1199 |
- cloneRepository = buildMergingRepository(pullRequest); |
|
1200 |
- |
|
1201 |
- String srcToBranchName = pullRequest.toBranch; |
|
1202 |
- String destToBranchName = makeDestToBranchName(pullRequest); |
|
1203 |
- String srcFromBranchName = pullRequest.fromBranch; |
|
1204 |
- destFromBranchName = makeDestFromBranchName(pullRequest); |
|
1205 |
- mergingBranch = "" + System.currentTimeMillis(); |
|
1206 |
- |
|
1207 |
- new Git(cloneRepository).fetch() |
|
1208 |
- .setRemote(GitRepository.getGitDirectoryURL(pullRequest.fromProject)) |
|
1209 |
- .setRefSpecs(new RefSpec("+" + srcFromBranchName + ":" + destFromBranchName)) |
|
1210 |
- .call(); |
|
1211 |
- |
|
1212 |
- new Git(cloneRepository).fetch() |
|
1213 |
- .setRemote(GitRepository.getGitDirectoryURL(pullRequest.toProject)) |
|
1214 |
- .setRefSpecs(new RefSpec("+" + srcToBranchName + ":" + destToBranchName)) |
|
1215 |
- .call(); |
|
1216 |
- |
|
1217 |
- resetAndClean(cloneRepository); |
|
1218 |
- |
|
1219 |
- new Git(cloneRepository).checkout() |
|
1220 |
- .setCreateBranch(true) |
|
1221 |
- .setName(mergingBranch) |
|
1222 |
- .setStartPoint(destToBranchName) |
|
1223 |
- .call(); |
|
1224 |
- |
|
1225 |
- CloneAndFetch cloneAndFetch = new CloneAndFetch(cloneRepository, destToBranchName, destFromBranchName, mergingBranch); |
|
1226 |
- operation.invoke(cloneAndFetch); |
|
1227 |
- |
|
1228 |
- resetAndClean(cloneRepository); |
|
1229 |
- |
|
1230 |
- new Git(cloneRepository).checkout().setName(destToBranchName).call(); |
|
1231 |
- new Git(cloneRepository).branchDelete().setForce(true).setBranchNames(mergingBranch).call(); |
|
1232 |
- } |
|
1233 |
- } catch (GitAPIException e) { |
|
1234 |
- throw new IllegalStateException(e); |
|
1235 |
- } catch (IOException e) { |
|
1236 |
- throw new IllegalStateException(e); |
|
1237 |
- } finally { |
|
1238 |
- if(cloneRepository != null) { |
|
1239 |
- cloneRepository.close(); |
|
1240 |
- } |
|
1241 |
- } |
|
1242 |
- } |
|
1243 |
- |
|
1244 |
- private static void resetAndClean(Repository cloneRepository) throws GitAPIException { |
|
1245 |
- new Git(cloneRepository).reset().setMode(ResetCommand.ResetType.HARD).setRef(Constants.HEAD).call(); |
|
1246 |
- new Git(cloneRepository).clean().setIgnore(true).setCleanDirectories(true).call(); |
|
1247 |
- } |
|
1248 |
- |
|
1249 |
- private static String makeDestToBranchName(PullRequest pullRequest) { |
|
1250 |
- return Constants.R_REMOTES + |
|
1251 |
- pullRequest.toProject.owner + "/" + |
|
1252 |
- pullRequest.toProject.name + "/" + |
|
1253 |
- pullRequest.toBranch.replaceFirst(Constants.R_HEADS, ""); |
|
1254 |
- } |
|
1255 |
- |
|
1256 |
- private static String makeDestFromBranchName(PullRequest pullRequest) { |
|
1257 |
- return Constants.R_REMOTES + |
|
1258 |
- pullRequest.fromProject.owner + "/" + |
|
1259 |
- pullRequest.fromProject.name + "/" + |
|
1260 |
- pullRequest.fromBranch.replaceFirst(Constants.R_HEADS, ""); |
|
1261 | 1113 |
} |
1262 | 1114 |
|
1263 | 1115 |
public static Repository buildMergingRepository(PullRequest pullRequest) { |
... | ... | @@ -1805,9 +1657,6 @@ |
1805 | 1657 |
} |
1806 | 1658 |
} |
1807 | 1659 |
|
1808 |
- /** |
|
1809 |
- * @see #cloneAndFetch(models.PullRequest, playRepository.GitRepository.AfterCloneAndFetchOperation) |
|
1810 |
- */ |
|
1811 | 1660 |
public static interface AfterCloneAndFetchOperation { |
1812 | 1661 |
public void invoke(CloneAndFetch cloneAndFetch) throws IOException, GitAPIException; |
1813 | 1662 |
} |
--- app/views/git/partial_state.scala.html
+++ app/views/git/partial_state.scala.html
... | ... | @@ -44,14 +44,6 @@ |
44 | 44 |
<div class="alert alert-error"> |
45 | 45 |
<i class="yobicon-error mr5"></i> |
46 | 46 |
<span>@Messages("pullRequest.is.not.safe")</span> |
47 |
- <div> |
|
48 |
- <h6>@Messages("pullRequest.conflict.files")</h6> |
|
49 |
- <ul class="unstyled conflict-files"> |
|
50 |
- @for(file <- pull.getConflictFiles) { |
|
51 |
- <li>@file</li> |
|
52 |
- } |
|
53 |
- </ul> |
|
54 |
- </div> |
|
55 | 47 |
|
56 | 48 |
@if(UserApp.currentUser().equals(pull.contributor)){ |
57 | 49 |
<div class="howto-resolve-conflict"> |
+++ conf/evolutions/default/90.sql
... | ... | @@ -0,0 +1,7 @@ |
1 | +# --- !Ups | |
2 | + | |
3 | +ALTER TABLE pull_request DROP COLUMN conflict_files; | |
4 | + | |
5 | +# --- !Downs | |
6 | + | |
7 | +ALTER TABLE pull_request ADD COLUMN conflict_files clob; |
--- test/controllers/ImportAppTest.java
+++ test/controllers/ImportAppTest.java
... | ... | @@ -53,7 +53,6 @@ |
53 | 53 |
@BeforeClass |
54 | 54 |
public static void before() throws Exception { |
55 | 55 |
GitRepository.setRepoPrefix("resources/test/repo/git/"); |
56 |
- GitRepository.setRepoForMergingPrefix("resources/test/repo/git-merging/"); |
|
57 | 56 |
application = support.Helpers.makeTestApplication(); |
58 | 57 |
start(application); |
59 | 58 |
yobi = User.findByLoginId("yobi"); |
... | ... | @@ -67,7 +66,6 @@ |
67 | 66 |
public static void after() { |
68 | 67 |
stop(application); |
69 | 68 |
support.Files.rm_rf(new File(GitRepository.getRepoPrefix())); |
70 |
- support.Files.rm_rf(new File(GitRepository.getRepoForMergingPrefix())); |
|
71 | 69 |
} |
72 | 70 |
|
73 | 71 |
@Test |
--- test/controllers/PullRequestAppTest.java
+++ test/controllers/PullRequestAppTest.java
... | ... | @@ -73,7 +73,6 @@ |
73 | 73 |
@Before |
74 | 74 |
public void before() { |
75 | 75 |
GitRepository.setRepoPrefix("resources/test/repo/git/"); |
76 |
- GitRepository.setRepoForMergingPrefix("resources/test/repo/git-merging/"); |
|
77 | 76 |
} |
78 | 77 |
|
79 | 78 |
@AfterClass |
... | ... | @@ -84,7 +83,6 @@ |
84 | 83 |
@After |
85 | 84 |
public void after() { |
86 | 85 |
support.Files.rm_rf(new File(GitRepository.getRepoPrefix())); |
87 |
- support.Files.rm_rf(new File(GitRepository.getRepoForMergingPrefix())); |
|
88 | 86 |
} |
89 | 87 |
|
90 | 88 |
@Test |
... | ... | @@ -388,33 +386,6 @@ |
388 | 386 |
this.ownerLoginId = ownerLoginId; |
389 | 387 |
this.projectName = projectName; |
390 | 388 |
this.pullRequestNumber = pullRequestNumber; |
391 |
- Project project = Project.findByOwnerAndProjectName(ownerLoginId, projectName); |
|
392 |
- PullRequest pullRequest = PullRequest.findOne(project, pullRequestNumber); |
|
393 |
- initRepositories(pullRequest); |
|
394 | 389 |
} |
395 | 390 |
|
396 |
- private void initRepositories(PullRequest pullRequest) throws Exception { |
|
397 |
- if (pullRequest == null) { |
|
398 |
- return; |
|
399 |
- } |
|
400 |
- initRepository(pullRequest.toProject, |
|
401 |
- StringUtils.removeStart(pullRequest.toBranch, "refs/heads/"), "1.txt"); |
|
402 |
- initRepository(pullRequest.fromProject, |
|
403 |
- StringUtils.removeStart(pullRequest.fromBranch, "refs/heads/"), "2.txt"); |
|
404 |
- } |
|
405 |
- |
|
406 |
- private void initRepository(Project project, String branchName, String fileName) throws Exception { |
|
407 |
- GitRepository gitRepository = new GitRepository(project); |
|
408 |
- gitRepository.create(); |
|
409 |
- |
|
410 |
- Repository repository = GitRepository.buildMergingRepository(project); |
|
411 |
- Git git = new Git(repository); |
|
412 |
- |
|
413 |
- FileUtils.touch(new File(GitRepository.getDirectoryForMerging(project.owner, project.name + "/" + fileName))); |
|
414 |
- git.add().addFilepattern(fileName).call(); |
|
415 |
- git.commit().setMessage(fileName).call(); |
|
416 |
- git.push().setRefSpecs(new RefSpec("master:master"), new RefSpec("master:" + branchName)).call(); |
|
417 |
- gitRepository.close(); |
|
418 |
- repository.close(); |
|
419 |
- } |
|
420 | 391 |
} |
--- test/models/CodeCommentThreadTest.java
+++ test/models/CodeCommentThreadTest.java
... | ... | @@ -28,6 +28,7 @@ |
28 | 28 |
import org.junit.Test; |
29 | 29 |
import playRepository.BareCommit; |
30 | 30 |
import playRepository.GitRepository; |
31 |
+import support.Git; |
|
31 | 32 |
import utils.JodaDateUtil; |
32 | 33 |
|
33 | 34 |
import java.io.File; |
... | ... | @@ -41,7 +42,6 @@ |
41 | 42 |
* @author Changsung Kim |
42 | 43 |
*/ |
43 | 44 |
public class CodeCommentThreadTest extends ModelTest<CodeCommentThread> { |
44 |
- private static final String MERGING_REPO_PREFIX = "resources/test/repo/git-merging/"; |
|
45 | 45 |
private static final String REPO_PREFIX = "resources/test/repo/git/"; |
46 | 46 |
private Project project; |
47 | 47 |
private ObjectId baseCommit; |
... | ... | @@ -57,12 +57,10 @@ |
57 | 57 |
@After |
58 | 58 |
public void after() { |
59 | 59 |
rm_rf(new File(REPO_PREFIX)); |
60 |
- rm_rf(new File(MERGING_REPO_PREFIX)); |
|
61 | 60 |
} |
62 | 61 |
|
63 | 62 |
private void addTestRepository() throws IOException, GitAPIException { |
64 | 63 |
GitRepository.setRepoPrefix(REPO_PREFIX); |
65 |
- GitRepository.setRepoForMergingPrefix(MERGING_REPO_PREFIX); |
|
66 | 64 |
|
67 | 65 |
// given |
68 | 66 |
GitRepository.buildGitRepository(project).create(true); |
--- test/models/PullRequestTest.java
+++ test/models/PullRequestTest.java
... | ... | @@ -47,7 +47,6 @@ |
47 | 47 |
import static utils.FileUtil.rm_rf; |
48 | 48 |
|
49 | 49 |
public class PullRequestTest extends ModelTest<PullRequest> { |
50 |
- private static final String MERGING_REPO_PREFIX = "resources/test/repo/git-merging/"; |
|
51 | 50 |
private static final String REPO_PREFIX = "resources/test/repo/git/"; |
52 | 51 |
private static final String LOCAL_REPO_PREFIX = "resources/test/local-repo/git/"; |
53 | 52 |
|
... | ... | @@ -61,7 +60,6 @@ |
61 | 60 |
public void initRepositories() throws IOException, GitAPIException, ServletException, |
62 | 61 |
ClientException, PullRequestException { |
63 | 62 |
GitRepository.setRepoPrefix(REPO_PREFIX); |
64 |
- GitRepository.setRepoForMergingPrefix(MERGING_REPO_PREFIX); |
|
65 | 63 |
|
66 | 64 |
app = support.Helpers.makeTestApplication(); |
67 | 65 |
Helpers.start(app); |
... | ... | @@ -80,7 +78,7 @@ |
80 | 78 |
.setDirectory(new File(localRepoPath)) |
81 | 79 |
.call(); |
82 | 80 |
Repository repo = git.getRepository(); |
83 |
- baseCommit = support.Git.commit(repo, repo.getWorkTree().getAbsolutePath(), "test.txt", |
|
81 |
+ baseCommit = support.Git.commit(repo, "test.txt", |
|
84 | 82 |
"apple\nbanana\ncat\n", "commit 1"); |
85 | 83 |
git.push().setRefSpecs(new RefSpec("+refs/heads/master:refs/heads/master")).call(); |
86 | 84 |
} |
... | ... | @@ -99,9 +97,9 @@ |
99 | 97 |
git.checkout().setName("fix/1").call(); |
100 | 98 |
Repository repo = git.getRepository(); |
101 | 99 |
assertThat(repo.isBare()).describedAs("projectYobi-1 must be non-bare").isFalse(); |
102 |
- firstCommit = support.Git.commit(repo, repo.getWorkTree().getAbsolutePath(), |
|
100 |
+ firstCommit = support.Git.commit(repo, |
|
103 | 101 |
"test.txt", "apple\nbanana\ncorn\n", "commit 1"); |
104 |
- secondCommit = support.Git.commit(repo, repo.getWorkTree().getAbsolutePath(), |
|
102 |
+ secondCommit = support.Git.commit(repo, |
|
105 | 103 |
"test.txt", "apple\nbanana\ncake\n", "commit 2"); |
106 | 104 |
git.push().setRefSpecs(new RefSpec("+refs/heads/fix/1:refs/heads/fix/1")).call(); |
107 | 105 |
} |
... | ... | @@ -120,7 +118,6 @@ |
120 | 118 |
@After |
121 | 119 |
public void after() { |
122 | 120 |
rm_rf(new File(REPO_PREFIX)); |
123 |
- rm_rf(new File(MERGING_REPO_PREFIX)); |
|
124 | 121 |
rm_rf(new File(LOCAL_REPO_PREFIX)); |
125 | 122 |
Helpers.stop(app); |
126 | 123 |
} |
--- test/playRepository/GitRepositoryTest.java
+++ test/playRepository/GitRepositoryTest.java
... | ... | @@ -20,24 +20,27 @@ |
20 | 20 |
*/ |
21 | 21 |
package playRepository; |
22 | 22 |
|
23 |
-import static play.test.Helpers.*; |
|
24 | 23 |
import models.Project; |
25 | 24 |
import models.PullRequest; |
26 | 25 |
import models.User; |
27 |
- |
|
28 | 26 |
import org.apache.commons.io.FileUtils; |
29 | 27 |
import org.codehaus.jackson.node.ObjectNode; |
30 | 28 |
import org.eclipse.jgit.api.CommitCommand; |
31 | 29 |
import org.eclipse.jgit.api.Git; |
32 | 30 |
import org.eclipse.jgit.api.errors.GitAPIException; |
33 |
-import org.eclipse.jgit.lib.*; |
|
31 |
+import org.eclipse.jgit.lib.Constants; |
|
32 |
+import org.eclipse.jgit.lib.Ref; |
|
33 |
+import org.eclipse.jgit.lib.Repository; |
|
34 |
+import org.eclipse.jgit.lib.RepositoryBuilder; |
|
34 | 35 |
import org.eclipse.jgit.revwalk.RevCommit; |
35 | 36 |
import org.eclipse.jgit.revwalk.RevTree; |
36 | 37 |
import org.eclipse.jgit.revwalk.RevWalk; |
37 | 38 |
import org.eclipse.jgit.transport.RefSpec; |
38 | 39 |
import org.eclipse.jgit.treewalk.TreeWalk; |
39 |
-import org.junit.*; |
|
40 |
- |
|
40 |
+import org.junit.After; |
|
41 |
+import org.junit.Before; |
|
42 |
+import org.junit.Rule; |
|
43 |
+import org.junit.Test; |
|
41 | 44 |
import org.junit.rules.TestWatcher; |
42 | 45 |
import play.test.FakeApplication; |
43 | 46 |
import play.test.Helpers; |
... | ... | @@ -53,6 +56,7 @@ |
53 | 56 |
|
54 | 57 |
import static org.fest.assertions.Assertions.assertThat; |
55 | 58 |
import static org.fest.assertions.Fail.fail; |
59 |
+import static play.test.Helpers.running; |
|
56 | 60 |
|
57 | 61 |
public class GitRepositoryTest { |
58 | 62 |
|
... | ... | @@ -62,13 +66,11 @@ |
62 | 66 |
@Before |
63 | 67 |
public void before() { |
64 | 68 |
GitRepository.setRepoPrefix("resources/test/repo/git/"); |
65 |
- GitRepository.setRepoForMergingPrefix("resources/test/repo/git-merging/"); |
|
66 | 69 |
} |
67 | 70 |
|
68 | 71 |
@After |
69 | 72 |
public void after() { |
70 | 73 |
support.Files.rm_rf(new File(GitRepository.getRepoPrefix())); |
71 |
- support.Files.rm_rf(new File(GitRepository.getRepoForMergingPrefix())); |
|
72 | 74 |
} |
73 | 75 |
|
74 | 76 |
@Test |
... | ... | @@ -217,57 +219,6 @@ |
217 | 219 |
assertThat(file.exists()).isTrue(); |
218 | 220 |
} |
219 | 221 |
|
220 |
- @Test |
|
221 |
- public void cloneRepositoryWithNonBareMode() throws IOException, GitAPIException { |
|
222 |
- // Given |
|
223 |
- Project originProject = createProject("whiteship", "test"); |
|
224 |
- support.Files.rm_rf(new File(GitRepository.getGitDirectory(originProject))); |
|
225 |
- new GitRepository(originProject.owner, originProject.name).create(); |
|
226 |
- |
|
227 |
- String cloneWorkingTreePath = GitRepository.getDirectoryForMerging(originProject.owner, originProject.name); |
|
228 |
- support.Files.rm_rf(new File(cloneWorkingTreePath)); |
|
229 |
- |
|
230 |
- // When |
|
231 |
- Git.cloneRepository() |
|
232 |
- .setURI(GitRepository.getGitDirectoryURL(originProject)) |
|
233 |
- .setDirectory(new File(cloneWorkingTreePath)) |
|
234 |
- .call(); |
|
235 |
- |
|
236 |
- // Then |
|
237 |
- assertThat(new File(cloneWorkingTreePath).exists()).isTrue(); |
|
238 |
- assertThat(new File(cloneWorkingTreePath + "/.git").exists()).isTrue(); |
|
239 |
- |
|
240 |
- Repository cloneRepository = new RepositoryBuilder() |
|
241 |
- .setWorkTree(new File(cloneWorkingTreePath)) |
|
242 |
- .setGitDir(new File(cloneWorkingTreePath + "/.git")) |
|
243 |
- .build(); |
|
244 |
- |
|
245 |
- assertThat(cloneRepository.getFullBranch()).isEqualTo("refs/heads/master"); |
|
246 |
- |
|
247 |
- // When |
|
248 |
- Git cloneGit = new Git(cloneRepository); |
|
249 |
- |
|
250 |
- // toProject를 clone 받은 워킹 디렉토리에서 테스트 파일 만들고 커밋하고 푸쉬하기 |
|
251 |
- String readmeFileName = "readme.md"; |
|
252 |
- String testFilePath = cloneWorkingTreePath + "/" + readmeFileName; |
|
253 |
- BufferedWriter out = new BufferedWriter(new FileWriter(testFilePath)); |
|
254 |
- out.write("hello 1"); |
|
255 |
- out.flush(); |
|
256 |
- cloneGit.add().addFilepattern(readmeFileName).call(); |
|
257 |
- cloneGit.commit().setMessage("commit 1").call(); |
|
258 |
- cloneGit.push().call(); |
|
259 |
- |
|
260 |
- // Then |
|
261 |
- Repository originRepository = GitRepository.buildGitRepository(originProject); |
|
262 |
- String readmeFileInClone = new String(getRawFile(cloneRepository, readmeFileName)); |
|
263 |
- assertThat(readmeFileInClone).isEqualTo("hello 1"); |
|
264 |
- String readmeFileInOrigin = new String(getRawFile(originRepository, readmeFileName)); |
|
265 |
- assertThat(readmeFileInOrigin).isEqualTo("hello 1"); |
|
266 |
- |
|
267 |
- cloneRepository.close(); |
|
268 |
- originRepository.close(); |
|
269 |
- } |
|
270 |
- |
|
271 | 222 |
|
272 | 223 |
@Test |
273 | 224 |
public void getMetaDataFromPath() throws Exception { |
... | ... | @@ -301,7 +252,7 @@ |
301 | 252 |
ObjectNode notExistBranch = gitRepository.getMetaDataFromPath("not_exist_branch", ""); |
302 | 253 |
ObjectNode root = gitRepository.getMetaDataFromPath(""); |
303 | 254 |
ObjectNode dir = gitRepository.getMetaDataFromPath("dir"); |
304 |
- ObjectNode file= gitRepository.getMetaDataFromPath("hello"); |
|
255 |
+ ObjectNode file = gitRepository.getMetaDataFromPath("hello"); |
|
305 | 256 |
ObjectNode branch = gitRepository.getMetaDataFromPath(branchName, ""); |
306 | 257 |
ObjectNode lightWeightTag = gitRepository.getMetaDataFromPath(lightWeightTagName, ""); |
307 | 258 |
ObjectNode annotatedTag = gitRepository.getMetaDataFromPath(annotatedTagName, ""); |
... | ... | @@ -325,35 +276,15 @@ |
325 | 276 |
} |
326 | 277 |
|
327 | 278 |
@Test |
328 |
- public void buildCloneRepository() throws GitAPIException, IOException { |
|
329 |
- // Given |
|
330 |
- Project original = createProject("keesun", "test"); |
|
331 |
- PullRequest pullRequest = createPullRequest(original); |
|
332 |
- new GitRepository("keesun", "test").create(); |
|
333 |
- |
|
334 |
- // When |
|
335 |
- Repository repository = GitRepository.buildMergingRepository(pullRequest); |
|
336 |
- |
|
337 |
- // Then |
|
338 |
- assertThat(repository).isNotNull(); |
|
339 |
- String repositoryWorkingDirectory = GitRepository.getDirectoryForMerging(original.owner, original.name); |
|
340 |
- assertThat(repositoryWorkingDirectory).isNotNull(); |
|
341 |
- String clonePath = "resources/test/repo/git-merging/keesun/test.git"; |
|
342 |
- assertThat(repositoryWorkingDirectory).isEqualTo(clonePath); |
|
343 |
- assertThat(new File(clonePath).exists()).isTrue(); |
|
344 |
- assertThat(new File(clonePath + "/.git").exists()).isTrue(); |
|
345 |
- } |
|
346 |
- |
|
347 |
- @Test |
|
348 | 279 |
public void deleteBranch() throws IOException, GitAPIException { |
349 | 280 |
// given |
350 |
- Repository repository = createRepository("keesun", "test", false); |
|
281 |
+ Repository repository = support.Git.createRepository("keesun", "test", false); |
|
351 | 282 |
Git git = new Git(repository); |
352 | 283 |
|
353 | 284 |
String fileName = "readme.md"; |
354 | 285 |
String contents = "Hello World"; |
355 | 286 |
String commitMessage = "Initial commit"; |
356 |
- addCommit(git, fileName, contents, commitMessage); |
|
287 |
+ addCommit(git, fileName, contents, commitMessage, null); |
|
357 | 288 |
|
358 | 289 |
git.branchCreate().setName("develop").setForce(true).call(); |
359 | 290 |
GitRepository.checkout(repository, "develop"); |
... | ... | @@ -371,151 +302,19 @@ |
371 | 302 |
} |
372 | 303 |
} |
373 | 304 |
|
374 |
- public Repository createRepository(String userName, String projectName, boolean bare) throws IOException { |
|
375 |
- String wcPath = GitRepository.getRepoPrefix() + userName + "/" + projectName; |
|
376 |
- String repoPath = wcPath + "/.git"; |
|
377 |
- File repoDir = new File(repoPath); |
|
378 |
- Repository repository = new RepositoryBuilder().setGitDir(repoDir).build(); |
|
379 |
- repository.create(bare); |
|
380 |
- return repository; |
|
381 |
- } |
|
382 |
- |
|
383 |
- public void addCommit(Git git, String fileName, String contents, String commitMessage) throws IOException, GitAPIException { |
|
305 |
+ public RevCommit addCommit(Git git, String fileName, String contents, String commitMessage, |
|
306 |
+ User author) throws IOException, GitAPIException { |
|
384 | 307 |
File newFile = new File(git.getRepository().getWorkTree().getAbsolutePath(), fileName); |
385 | 308 |
BufferedWriter out = new BufferedWriter(new FileWriter(newFile)); |
386 | 309 |
out.write(contents); |
387 | 310 |
out.flush(); |
388 | 311 |
git.add().addFilepattern(fileName).call(); |
389 |
- git.commit().setMessage(commitMessage).call(); |
|
390 |
- } |
|
391 |
- |
|
392 |
- @Test |
|
393 |
- public void fetch() throws IOException, GitAPIException { |
|
394 |
- // Given |
|
395 |
- Project original = createProject("keesun", "test"); |
|
396 |
- PullRequest pullRequest = createPullRequest(original); |
|
397 |
- new GitRepository(original).create(); |
|
398 |
- Repository repository = GitRepository.buildMergingRepository(pullRequest); |
|
399 |
- |
|
400 |
- RevCommit commit = newCommit(original, repository, "readme.md", "hello 1", "commit 1"); |
|
401 |
- new Git(repository).push().call(); |
|
402 |
- |
|
403 |
- // When |
|
404 |
- String dstBranchName = "refs/heads/master-fetch"; |
|
405 |
- GitRepository.fetch(repository, original, "refs/heads/master", dstBranchName); |
|
406 |
- |
|
407 |
- // Then |
|
408 |
- ObjectId branch = repository.resolve(dstBranchName); |
|
409 |
- assertThat(branch.getName()).isEqualTo(commit.getId().getName()); |
|
410 |
- } |
|
411 |
- |
|
412 |
- private RevCommit newCommit(Project project, Repository repository, String fileName, String content, String message) throws IOException, GitAPIException { |
|
413 |
- return newCommit(project, repository, fileName, content, message, null); |
|
414 |
- } |
|
415 |
- |
|
416 |
- private RevCommit newCommit(Project project, Repository repository, String fileName, |
|
417 |
- String content, String message, User author) throws IOException, GitAPIException { |
|
418 |
- String workingTreePath = GitRepository.getDirectoryForMerging(project.owner, project.name); |
|
419 |
- String testFilePath = workingTreePath + "/" + fileName; |
|
420 |
- BufferedWriter out = new BufferedWriter(new FileWriter(testFilePath)); |
|
421 |
- out.write(content); |
|
422 |
- out.flush(); |
|
423 |
- out.close(); |
|
424 |
- |
|
425 |
- Git git = new Git(repository); |
|
426 |
- git.add().addFilepattern(fileName).call(); |
|
427 |
- CommitCommand commitCommand = git.commit().setMessage(message); |
|
312 |
+ CommitCommand commit = git.commit().setMessage(commitMessage); |
|
428 | 313 |
if (author != null) { |
429 |
- commitCommand |
|
430 |
- .setAuthor(author.loginId, author.email) |
|
431 |
- .setCommitter(author.loginId, author.email); |
|
314 |
+ commit.setAuthor(author.loginId, author.email) |
|
315 |
+ .setCommitter(author.loginId, author.email); |
|
432 | 316 |
} |
433 |
- return commitCommand.call(); |
|
434 |
- } |
|
435 |
- |
|
436 |
- @Test |
|
437 |
- public void checkout() throws IOException, GitAPIException { |
|
438 |
- // Given |
|
439 |
- Project original = createProject("keesun", "test"); |
|
440 |
- PullRequest pullRequest = createPullRequest(original); |
|
441 |
- new GitRepository(original).create(); |
|
442 |
- Repository repository = GitRepository.buildMergingRepository(pullRequest); |
|
443 |
- // 커밋이 없으면 HEAD도 없어서 브랜치 만들 때 에러가 발생하기 때문에 일단 하나 커밋한다. |
|
444 |
- newCommit(original, repository, "readme.md", "hello 1", "commit 1"); |
|
445 |
- |
|
446 |
- Git git = new Git(repository); |
|
447 |
- String branchName = "new-branch"; |
|
448 |
- git.branchCreate() |
|
449 |
- .setName(branchName) |
|
450 |
- .setForce(true) |
|
451 |
- .call(); |
|
452 |
- |
|
453 |
- // When |
|
454 |
- GitRepository.checkout(repository, branchName); |
|
455 |
- |
|
456 |
- // Then |
|
457 |
- assertThat(repository.getFullBranch()).isEqualTo("refs/heads/" + branchName); |
|
458 |
- } |
|
459 |
- |
|
460 |
- @Test |
|
461 |
- public void merge() throws IOException, GitAPIException { |
|
462 |
- // Given |
|
463 |
- Project original = createProject("keesun", "test"); |
|
464 |
- PullRequest pullRequest = createPullRequest(original); |
|
465 |
- GitRepository gitRepository = new GitRepository(original); |
|
466 |
- gitRepository.create(); |
|
467 |
- Repository repository = GitRepository.buildMergingRepository(pullRequest); |
|
468 |
- |
|
469 |
- // master에 commit 1 추가 |
|
470 |
- newCommit(original, repository, "readme.md", "hello 1", "commit 1"); |
|
471 |
- // new-branch 생성 |
|
472 |
- Git git = new Git(repository); |
|
473 |
- String branchName = "new-branch"; |
|
474 |
- git.branchCreate() |
|
475 |
- .setName(branchName) |
|
476 |
- .setForce(true) |
|
477 |
- .call(); |
|
478 |
- // new-branch 로 이동 |
|
479 |
- GitRepository.checkout(repository, branchName); |
|
480 |
- // new-branch에 commit 2 추가 |
|
481 |
- String fileName = "hello.md"; |
|
482 |
- String content = "hello 2"; |
|
483 |
- newCommit(original, repository, fileName, content, "commit 2"); |
|
484 |
- |
|
485 |
- // master 로 이동 |
|
486 |
- GitRepository.checkout(repository, "master"); |
|
487 |
- // When |
|
488 |
- GitRepository.merge(repository, branchName); |
|
489 |
- // Then |
|
490 |
- assertThat(new String(getRawFile(repository, fileName))).isEqualTo(content); |
|
491 |
- |
|
492 |
- gitRepository.close(); |
|
493 |
- repository.close(); |
|
494 |
- } |
|
495 |
- |
|
496 |
- @Test |
|
497 |
- public void push() throws IOException, GitAPIException { |
|
498 |
- // Given |
|
499 |
- Project original = createProject("keesun", "test"); |
|
500 |
- PullRequest pullRequest = createPullRequest(original); |
|
501 |
- new GitRepository(original).create(); |
|
502 |
- Repository repository = GitRepository.buildMergingRepository(pullRequest); |
|
503 |
- // master에 commit 1 추가 |
|
504 |
- String fileName = "readme.md"; |
|
505 |
- String content = "hello 1"; |
|
506 |
- newCommit(original, repository, fileName, content, "commit 1"); |
|
507 |
- |
|
508 |
- // When |
|
509 |
- String branchName = "master"; |
|
510 |
- GitRepository.push(repository, GitRepository.getGitDirectoryURL(original), branchName, branchName); |
|
511 |
- |
|
512 |
- // Then |
|
513 |
- Repository originalRepo = new RepositoryBuilder() |
|
514 |
- .setGitDir(new File(GitRepository.getGitDirectory(original))) |
|
515 |
- .build(); |
|
516 |
- assertThat(new String(getRawFile(originalRepo, fileName))).isEqualTo(content); |
|
517 |
- |
|
518 |
- originalRepo.close(); |
|
317 |
+ return commit.call(); |
|
519 | 318 |
} |
520 | 319 |
|
521 | 320 |
@Test |
... | ... | @@ -608,21 +407,19 @@ |
608 | 407 |
FakeApplication app = support.Helpers.makeTestApplication(); |
609 | 408 |
Helpers.start(app); |
610 | 409 |
|
611 |
- Project project = createProject("yobi", "test"); |
|
612 |
- PullRequest pullRequest = createPullRequest(project); |
|
613 |
- GitRepository gitRepository = new GitRepository(project); |
|
614 |
- gitRepository.create(); |
|
615 |
- Repository repository = GitRepository.buildMergingRepository(pullRequest); |
|
410 |
+ Repository repository = support.Git.createRepository("yobi", "test", true); |
|
616 | 411 |
|
617 | 412 |
// Given |
618 | 413 |
User yobi = User.findByLoginId("yobi"); |
619 | 414 |
User laziel = User.findByLoginId("laziel"); |
620 | 415 |
User doortts = User.findByLoginId("doortts"); |
621 | 416 |
User nori = User.findByLoginId("nori"); |
622 |
- RevCommit from = newCommit(project, repository, "README.md", "hello", "1st commit", yobi); |
|
623 |
- newCommit(project, repository, "test.txt", "text file", "2nd commit", laziel); |
|
624 |
- newCommit(project, repository, "test.txt", "edited text file", "3rd commit", doortts); |
|
625 |
- RevCommit to = newCommit(project, repository, "README.md", "hello, world!", "4th commit", nori); |
|
417 |
+ |
|
418 |
+ Git git = new Git(repository); |
|
419 |
+ RevCommit from = addCommit(git, "README.md", "hello", "1st commit", yobi); |
|
420 |
+ addCommit(git, "test.txt", "text file", "2nd commit", laziel); |
|
421 |
+ addCommit(git, "test.txt", "edited text file", "3rd commit", doortts); |
|
422 |
+ RevCommit to = addCommit(git, "README.md", "hello, world!", "4th commit", nori); |
|
626 | 423 |
|
627 | 424 |
// When |
628 | 425 |
Set<User> authors = GitRepository.getRelatedAuthors(repository, from.getName(), to.getName()); |
... | ... | @@ -630,66 +427,8 @@ |
630 | 427 |
// Then |
631 | 428 |
assertThat(authors).containsOnly(yobi); |
632 | 429 |
|
633 |
- gitRepository.close(); |
|
430 |
+ repository.close(); |
|
634 | 431 |
Helpers.stop(app); |
635 |
- } |
|
636 |
- |
|
637 |
- @Test |
|
638 |
- public void testCloneAndFetch() throws IOException, GitAPIException { |
|
639 |
- // Given |
|
640 |
- Project original = createProject("keesun", "test"); |
|
641 |
- GitRepository gitRepository = new GitRepository(original); |
|
642 |
- gitRepository.create(); |
|
643 |
- |
|
644 |
- // original master에 커밋 하나를 push한다. |
|
645 |
- Repository noneBareClone = GitRepository.buildMergingRepository(original); |
|
646 |
- newCommit(original, noneBareClone, "README.md", "hello", "first commit"); |
|
647 |
- GitRepository.push(noneBareClone, GitRepository.getGitDirectoryURL(original), Constants.MASTER, Constants.MASTER); |
|
648 |
- |
|
649 |
- // feature 브랜치를 만들고 feature 브랜치로 이동해서 두번째 커밋을 작성하고 original의 feature 브랜치로 push한다. |
|
650 |
- String featureBranchName = "feature"; |
|
651 |
- new Git(noneBareClone).branchCreate().setName(featureBranchName).setForce(true).call(); |
|
652 |
- final String branchName = Constants.R_HEADS + featureBranchName; |
|
653 |
- new Git(noneBareClone).checkout().setName(branchName).call(); |
|
654 |
- newCommit(original, noneBareClone, "README.md", "world", "second commit"); |
|
655 |
- GitRepository.push(noneBareClone, GitRepository.getGitDirectoryURL(original), featureBranchName, featureBranchName); |
|
656 |
- |
|
657 |
- // feature 브랜치에서 master 브랜치로 코드를 보낸다. |
|
658 |
- final PullRequest pullRequest = createPullRequest(original); |
|
659 |
- pullRequest.toProject = original; |
|
660 |
- pullRequest.fromProject = original; |
|
661 |
- pullRequest.toBranch = Constants.R_HEADS + Constants.MASTER; |
|
662 |
- pullRequest.fromBranch = branchName; |
|
663 |
- |
|
664 |
- // When && Then |
|
665 |
- GitRepository.cloneAndFetch(pullRequest, new GitRepository.AfterCloneAndFetchOperation() { |
|
666 |
- @Override |
|
667 |
- public void invoke(GitRepository.CloneAndFetch cloneAndFetch) throws IOException, GitAPIException { |
|
668 |
- Repository repo = cloneAndFetch.getRepository(); |
|
669 |
- // 현재 위치가 코드를 merging하는 브랜치 인지 확인한다. |
|
670 |
- String fullBranch = repo.getFullBranch(); |
|
671 |
- assertThat(fullBranch).isEqualTo(cloneAndFetch.getMergingBranchName()); |
|
672 |
- |
|
673 |
- List<Ref> refs = new Git(repo).branchList().call(); |
|
674 |
- String fromBranchObjectId = null; |
|
675 |
- String toBranchObjectId = null; |
|
676 |
- for (Ref branchRef : refs) { |
|
677 |
- String name = branchRef.getObjectId().getName(); |
|
678 |
- if (branchRef.getName().equals(pullRequest.fromBranch)) { |
|
679 |
- fromBranchObjectId = name; |
|
680 |
- } |
|
681 |
- if (branchRef.getName().equals(pullRequest.toBranch)) { |
|
682 |
- toBranchObjectId = name; |
|
683 |
- } |
|
684 |
- } |
|
685 |
- |
|
686 |
- // from 브랜치와 to 브랜치를 fetch 받았는지 확인한다. |
|
687 |
- ObjectId fromObjectId = repo.resolve(cloneAndFetch.getDestFromBranchName()); |
|
688 |
- ObjectId toObjectId = repo.resolve(cloneAndFetch.getDestToBranchName()); |
|
689 |
- assertThat(fromObjectId.getName()).isEqualTo(fromBranchObjectId); |
|
690 |
- assertThat(toObjectId.getName()).isEqualTo(toBranchObjectId); |
|
691 |
- } |
|
692 |
- }); |
|
693 | 432 |
} |
694 | 433 |
|
695 | 434 |
private Project createProject(String owner, String name) { |
--- test/support/Git.java
+++ test/support/Git.java
... | ... | @@ -23,15 +23,19 @@ |
23 | 23 |
import org.eclipse.jgit.api.errors.GitAPIException; |
24 | 24 |
|
25 | 25 |
import org.eclipse.jgit.lib.Repository; |
26 |
+import org.eclipse.jgit.lib.RepositoryBuilder; |
|
26 | 27 |
import org.eclipse.jgit.revwalk.RevCommit; |
28 |
+import playRepository.GitRepository; |
|
27 | 29 |
|
28 | 30 |
import java.io.BufferedWriter; |
31 |
+import java.io.File; |
|
29 | 32 |
import java.io.FileWriter; |
30 | 33 |
import java.io.IOException; |
31 | 34 |
|
32 | 35 |
public class Git { |
33 |
- public static RevCommit commit(Repository repository, String wcPath, String fileName, |
|
36 |
+ public static RevCommit commit(Repository repository, String fileName, |
|
34 | 37 |
String contents, String commitMessage) throws IOException, GitAPIException { |
38 |
+ String wcPath = repository.getWorkTree().getAbsolutePath(); |
|
35 | 39 |
org.eclipse.jgit.api.Git git = new org.eclipse.jgit.api.Git(repository); |
36 | 40 |
BufferedWriter out = new BufferedWriter(new FileWriter(wcPath + "/" + fileName)); |
37 | 41 |
out.write(contents); |
... | ... | @@ -39,4 +43,13 @@ |
39 | 43 |
git.add().addFilepattern(fileName).call(); |
40 | 44 |
return git.commit().setMessage(commitMessage).call(); |
41 | 45 |
} |
46 |
+ |
|
47 |
+ public static Repository createRepository(String userName, String projectName, boolean bare) throws IOException { |
|
48 |
+ String wcPath = GitRepository.getRepoPrefix() + userName + "/" + projectName; |
|
49 |
+ String repoPath = wcPath + "/.git"; |
|
50 |
+ File repoDir = new File(repoPath); |
|
51 |
+ Repository repository = new RepositoryBuilder().setGitDir(repoDir).build(); |
|
52 |
+ repository.create(bare); |
|
53 |
+ return repository; |
|
54 |
+ } |
|
42 | 55 |
} |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?