Skip to content

Commit a64e22c

Browse files
author
Denis
committed
tests completed
1 parent 51a95e7 commit a64e22c

File tree

2 files changed

+16
-36
lines changed

2 files changed

+16
-36
lines changed

src/main/java/com/projectkaiser/scm/vcs/GitVCS.java

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.io.File;
44
import java.io.FileWriter;
55
import java.io.IOException;
6-
import java.io.InputStream;
76
import java.net.InetSocketAddress;
87
import java.net.Proxy;
98
import java.net.Proxy.Type;
@@ -21,19 +20,11 @@
2120
import org.eclipse.jgit.api.MergeResult;
2221
import org.eclipse.jgit.api.ResetCommand.ResetType;
2322
import org.eclipse.jgit.api.errors.GitAPIException;
24-
import org.eclipse.jgit.lib.Constants;
25-
import org.eclipse.jgit.lib.ObjectId;
26-
import org.eclipse.jgit.lib.ObjectLoader;
2723
import org.eclipse.jgit.lib.Repository;
28-
import org.eclipse.jgit.revwalk.RevCommit;
29-
import org.eclipse.jgit.revwalk.RevTree;
30-
import org.eclipse.jgit.revwalk.RevWalk;
3124
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
3225
import org.eclipse.jgit.transport.CredentialsProvider;
3326
import org.eclipse.jgit.transport.RefSpec;
3427
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
35-
import org.eclipse.jgit.treewalk.TreeWalk;
36-
import org.eclipse.jgit.treewalk.filter.PathFilter;
3728

3829
import com.projectkaiser.scm.vcs.api.AbstractVCS;
3930
import com.projectkaiser.scm.vcs.api.IVCS;
@@ -69,7 +60,6 @@ public void createBranch(String srcBranchName, String newBranchName, String comm
6960
git
7061
.branchCreate()
7162
.setName(newBranchName)
72-
.setForce(true)
7363
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
7464
.setStartPoint("origin/" + srcBranchName)
7565
.call();
@@ -107,7 +97,6 @@ public void deleteBranch(String branchName, String commitMessage) {
10797
git
10898
.branchDelete()
10999
.setBranchNames(branchName)
110-
.setForce(true)
111100
.call();
112101

113102
git
@@ -121,7 +110,6 @@ public void deleteBranch(String branchName, String commitMessage) {
121110
git
122111
.push()
123112
.setPushAll()
124-
.setForce(true)
125113
.setRefSpecs(refSpec)
126114
.setRemote("origin")
127115
.setCredentialsProvider(credentials)
@@ -160,8 +148,6 @@ public Git getLocalGit(VCSWorkspace workspace) {
160148
.setDirectory(workspace.getFolder())
161149
.setURI(baseUrl)
162150
.setCredentialsProvider(credentials)
163-
.setBranch("refs/heads/master")
164-
//.setCloneAllBranches(true)
165151
.setNoCheckout(true)
166152
.call();
167153
} catch (GitAPIException e) {
@@ -211,7 +197,7 @@ public PKVCSMergeResult merge(String sourceBranchUrl, String destBranchUrl, Stri
211197
.setMode(ResetType.HARD)
212198
.call();
213199
} catch(Exception e) {
214-
workspace.setIsCorrupt(true);
200+
workspace.setCorrupt(true);
215201
}
216202
} else {
217203
git
@@ -239,10 +225,7 @@ private void checkout(String destBranchUrl, Git git) throws GitAPIException {
239225
git
240226
.checkout()
241227
.setCreateBranch(false)
242-
.setForce(true)
243228
.setName(destBranchUrl)
244-
//.setStartPoint("origin/" + destBranchUrl)
245-
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
246229
.call();
247230
}
248231

@@ -297,11 +280,8 @@ public String getFileContent(String branchName, String filePath, String encoding
297280
git
298281
.checkout()
299282
.setCreateBranch(false)
300-
.setForce(true)
301283
.addPath(filePath)
302284
.setName(branchName)
303-
//.setStartPoint("origin/" + destBranchUrl)
304-
//.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
305285
.call();
306286
File file = new File(workspace.getFolder(), filePath);
307287

@@ -333,11 +313,8 @@ public void setFileContent(String branchName, String filePath, String content, S
333313
git
334314
.checkout()
335315
.setCreateBranch(false)
336-
.setForce(true)
337316
.addPath(filePath)
338317
.setName(branchName)
339-
//.setStartPoint("origin/" + destBranchUrl)
340-
//.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
341318
.call();
342319

343320
File file = new File(workspace.getFolder(), filePath);
@@ -355,7 +332,6 @@ public void setFileContent(String branchName, String filePath, String content, S
355332

356333
git
357334
.push()
358-
.setForce(true)
359335
.setRefSpecs(refSpec)
360336
.setRemote("origin")
361337
.setCredentialsProvider(credentials)

src/test/java/com/projectkaiser/scm/vcs/GitVCSTest.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import java.util.UUID;
1212
import java.util.function.Consumer;
1313

14-
import org.eclipse.jgit.api.CreateBranchCommand;
1514
import org.eclipse.jgit.api.Git;
1615
import org.eclipse.jgit.api.errors.GitAPIException;
1716
import org.eclipse.jgit.api.errors.NoFilepatternException;
@@ -152,55 +151,59 @@ public void testGitMerge() throws IOException, NoFilepatternException, GitAPIExc
152151
VCSWorkspace w = VCSWorkspace.getLockedWorkspace(gitVCS.getRepoFolder());
153152
try {
154153
try (Git git = gitVCS.getLocalGit(w)) {
154+
155+
git
156+
.checkout()
157+
.setCreateBranch(true)
158+
.setStartPoint("refs/remotes/origin/" + SRC_BRANCH)
159+
.setName(SRC_BRANCH)
160+
.call(); // switch to master
161+
155162
File file1 = new File(w.getFolder(), "file1.txt");
156163
file1.createNewFile();
157164

158165
git
159166
.add()
160167
.addFilepattern("file1.txt")
161168
.call();
169+
162170
git
163171
.commit()
164172
.setMessage(FILE1_ADDED_COMMIT_MESSAGE)
165173
.call();
166174

167175
git
176+
168177
.checkout()
169178
.setCreateBranch(false)
170-
171-
.setName(NEW_BRANCH) // create NEW_BRANCH locally
172-
.setForce(true)
173-
//.setStartPoint()
174-
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
179+
.setName(NEW_BRANCH)
175180
.call(); // switch to new-branch
176181

177182
File file2 = new File(w.getFolder(), "file2.txt");
178183
file2.createNewFile();
184+
179185
git
180186
.add()
181187
.addFilepattern("file2.txt")
182188
.call();
189+
183190
git
184191
.commit()
185192
.setMessage(FILE2_ADDED_COMMIT_MESSAGE)
186193
.call();
187194

188-
189195
git
190196
.push()
191197
.setPushAll()
192-
//.setForce(true)
193198
.setRemote("origin")
194199
.setCredentialsProvider(gitVCS.getCredentials())
195200
.call();
196201

197202
git
198203
.checkout()
199204
.setCreateBranch(false)
200-
.setForce(true)
205+
.setForce(false)
201206
.setName(SRC_BRANCH)
202-
//.setStartPoint("origin/" + SRC_BRANCH)
203-
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
204207
.call(); // switch to master
205208

206209
vcs.merge(NEW_BRANCH, SRC_BRANCH, MERGE_COMMIT_MESSAGE);
@@ -213,6 +216,7 @@ public void testGitMerge() throws IOException, NoFilepatternException, GitAPIExc
213216

214217
assertTrue(file1.exists());
215218
assertTrue(file2.exists());
219+
216220
Iterable<RevCommit> commits = git
217221
.log()
218222
.all()

0 commit comments

Comments
 (0)