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
|
/*******************************************************************************
* 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.egit.gitflow.GitFlowDefaults.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import java.io.File;
import org.eclipse.egit.core.op.BranchOperation;
import org.eclipse.egit.gitflow.GitFlowRepository;
import org.eclipse.jgit.api.MergeResult;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Test;
public class HotfixFinishOperationTest extends AbstractGitFlowOperationTest {
@Test
public void testHotfixFinish() throws Exception {
testRepository
.createInitialCommit("testHotfixFinish\n\nfirst commit\n");
Repository repository = testRepository.getRepository();
new InitOperation(repository).execute(null);
GitFlowRepository gfRepo = new GitFlowRepository(repository);
new HotfixStartOperation(gfRepo, MY_HOTFIX).execute(null);
RevCommit branchCommit = testRepository
.createInitialCommit("testHotfixFinish\n\nbranch commit\n");
new HotfixFinishOperation(gfRepo).execute(null);
assertEquals(gfRepo.getConfig().getDevelopFull(), repository.getFullBranch());
String branchName = gfRepo.getConfig().getHotfixBranchName(MY_HOTFIX);
// tag created?
assertEquals(branchCommit, gfRepo.findCommitForTag(MY_HOTFIX));
// branch removed?
assertEquals(findBranch(repository, branchName), null);
RevCommit developHead = gfRepo.findHead(DEVELOP);
assertEquals(branchCommit, developHead);
RevCommit masterHead = gfRepo.findHead(MY_MASTER);
assertEquals(branchCommit, masterHead);
}
@Test
public void testMergeToDevelopFail() throws Exception {
testRepository
.createInitialCommit("testMergeToDevelopFail\n\nfirst commit\n");
Repository repository = testRepository.getRepository();
new InitOperation(repository).execute(null);
GitFlowRepository gfRepo = new GitFlowRepository(repository);
// setup something we can modify later
File file = testRepository.createFile(project.getProject(),
"folder1/file1.txt");
new ReleaseStartOperation(gfRepo, MY_RELEASE).execute(null);
testRepository.appendContentAndCommit(project.getProject(), file,
"Hello Release", "Release Commit");
new ReleaseFinishOperation(gfRepo).execute(null);
new HotfixStartOperation(gfRepo, MY_HOTFIX).execute(null);
// modify on first branch
RevCommit hotfixCommit = testRepository.appendContentAndCommit(
project.getProject(), file, "Hello Hotfix", "Hotfix Commit");
new BranchOperation(repository, gfRepo.getConfig().getDevelop()).execute(null);
assertEquals(gfRepo.getConfig().getDevelopFull(), repository.getFullBranch());
// modify on second branch
RevCommit developCommit = testRepository.appendContentAndCommit(
project.getProject(), file, "Hello Develop", "Develop Commit");
String branchName = gfRepo.getConfig().getHotfixBranchName(MY_HOTFIX);
new BranchOperation(repository, branchName).execute(null);
HotfixFinishOperation hotfixFinishOperation = new HotfixFinishOperation(
gfRepo);
hotfixFinishOperation.execute(null);
// tag not created?
assertNotEquals(hotfixCommit, gfRepo.findCommitForTag(MY_HOTFIX));
// branch not removed?
assertNotEquals(findBranch(repository, branchName), null);
// not merged on develop => conflict
RevCommit developHead = gfRepo.findHead(DEVELOP);
assertEquals(developCommit, developHead);
assertEquals(MergeResult.MergeStatus.CONFLICTING, hotfixFinishOperation
.getMergeResult().getMergeStatus());
// merged on master
RevCommit masterHead = gfRepo.findHead(MY_MASTER);
assertEquals(hotfixCommit, masterHead);
assertEquals(gfRepo.getConfig().getDevelopFull(), repository.getFullBranch());
}
}
|