1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*******************************************************************************
* Copyright (C) 2015, Max Hohenegger <eclipse@hohenegger.eu>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.egit.gitflow.op;
import static org.eclipse.jgit.lib.Constants.DEFAULT_REMOTE_NAME;
import static org.eclipse.jgit.lib.Constants.DOT_GIT;
import static org.eclipse.jgit.lib.Constants.HEAD;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.egit.core.Activator;
import org.eclipse.egit.core.op.BranchOperation;
import org.eclipse.egit.core.op.CloneOperation;
import org.eclipse.egit.core.test.DualRepositoryTestCase;
import org.eclipse.egit.core.test.TestRepository;
import org.eclipse.egit.gitflow.GitFlowRepository;
import org.eclipse.jgit.errors.RevisionSyntaxException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.transport.URIish;
import org.junit.Before;
public class AbstractDualRepositoryTestCase extends DualRepositoryTestCase {
protected static final String MY_FEATURE = "myFeature";
protected static final String MY_MASTER = "master";
protected static final String MY_RELEASE = "myRelease";
protected static final String MY_VERSION_TAG = "v";
protected static final String MY_HOTFIX = "myHotfix";
private File workdir;
private File workdir2;
String projectName = "FeaturePublishTest";
@Override
@Before
public void beforeTestCase() throws Exception {
workdir = testUtils.createTempDir("Repository1");
workdir2 = testUtils.createTempDir("Repository2");
repository1 = new TestRepository(new File(workdir, DOT_GIT));
repository1.createInitialCommit("setUp");
Repository repository = repository1.getRepository();
new InitOperation(repository).execute(null);
// now we create a project in repo1
IProject project = testUtils.createProjectInLocalFileSystem(workdir,
projectName);
testUtils.addFileToProject(project, "folder1/file1.txt", "Hello world");
repository1.connect(project);
repository1.trackAllFiles(project);
repository1.commit("Initial commit");
// let's get rid of the project
project.delete(false, false, null);
// let's clone repository1 to repository2
URIish uri = repository1.getUri();
CloneOperation clop = new CloneOperation(uri, true, null, workdir2,
R_HEADS + MY_MASTER, DEFAULT_REMOTE_NAME, 0);
clop.run(null);
Repository repo2 = Activator.getDefault().getRepositoryCache()
.lookupRepository(new File(workdir2, DOT_GIT));
repository2 = new TestRepository(repo2);
new InitOperation(repository).execute(null);
}
protected void assertCommitArrivedAtRemote(RevCommit branchCommit,
Repository remote) throws CoreException {
GitFlowRepository gfRepo = new GitFlowRepository(remote);
BranchOperation checkoutOperation = new BranchOperation(remote,
gfRepo.getConfig().getFullFeatureBranchName(MY_FEATURE));
checkoutOperation.execute(null);
RevCommit developHead = findHead(remote);
assertEquals(branchCommit, developHead);
}
protected RevCommit findHead(Repository repo) {
try (RevWalk walk = new RevWalk(repo)) {
try {
ObjectId head = repo.resolve(HEAD);
return walk.parseCommit(head);
} catch (RevisionSyntaxException | IOException e) {
throw new RuntimeException(e);
}
}
}
protected String getRemoteName(GitFlowRepository gfRepo, String featureName) {
return gfRepo.getConfig().getRemoteName(featureName);
}
}
|