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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
/*******************************************************************************
* Copyright (c) 2016 Thomas Wolf <thomas.wolf@paranor.ch>
* 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.ui.test.team.actions;
import static org.eclipse.egit.ui.JobFamilies.ADD_TO_INDEX;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.egit.core.JobFamilies;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIPreferences;
import org.eclipse.egit.ui.common.LocalRepositoryTestCase;
import org.eclipse.egit.ui.internal.staging.StagingView;
import org.eclipse.egit.ui.test.ContextMenuHelper;
import org.eclipse.egit.ui.test.JobJoiner;
import org.eclipse.egit.ui.test.StagingUtil;
import org.eclipse.egit.ui.test.TestUtil;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests for the Team->Commit action
*/
@RunWith(SWTBotJunit4ClassRunner.class)
public class CommitActionStagingViewTest extends LocalRepositoryTestCase {
private File repositoryFile;
private boolean initialUseStagingView;
private boolean initialAutoStage;
@Before
public void setup() throws Exception {
TestUtil.hideView(StagingView.VIEW_ID);
initialUseStagingView = Activator.getDefault().getPreferenceStore()
.getBoolean(UIPreferences.ALWAYS_USE_STAGING_VIEW);
Activator.getDefault().getPreferenceStore()
.setValue(UIPreferences.ALWAYS_USE_STAGING_VIEW, true);
initialAutoStage = Activator.getDefault().getPreferenceStore()
.getBoolean(UIPreferences.AUTO_STAGE_ON_COMMIT);
Activator.getDefault().getPreferenceStore()
.setValue(UIPreferences.AUTO_STAGE_ON_COMMIT, false);
Activator.getDefault().getPreferenceStore()
.setDefault(UIPreferences.STAGING_VIEW_SYNC_SELECTION, false);
Activator.getDefault().getPreferenceStore()
.setValue(UIPreferences.STAGING_VIEW_SYNC_SELECTION, false);
repositoryFile = createProjectAndCommitToRepository();
Repository repo = lookupRepository(repositoryFile);
TestUtil.configureTestCommitterAsUser(repo);
// TODO delete the second project for the time being (.gitignore is
// currently not hiding the .project file from commit)
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ2);
File dotProject = new File(project.getLocation().toOSString(), ".project");
project.delete(false, false, null);
assertTrue(dotProject.delete());
}
@After
public void tearDown() {
Activator.getDefault().getPreferenceStore().setValue(
UIPreferences.ALWAYS_USE_STAGING_VIEW, initialUseStagingView);
Activator.getDefault().getPreferenceStore()
.setValue(UIPreferences.AUTO_STAGE_ON_COMMIT, initialAutoStage);
Activator.getDefault().getPreferenceStore()
.setDefault(UIPreferences.STAGING_VIEW_SYNC_SELECTION, true);
Activator.getDefault().getPreferenceStore()
.setValue(UIPreferences.STAGING_VIEW_SYNC_SELECTION, true);
}
@Test
public void testOpenStagingViewNoLinkWithSelection() throws Exception {
setTestFileContent("I have changed this");
SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
util.getProjectItems(projectExplorerTree, PROJ1)[0].select();
String menuString = util.getPluginLocalizedValue("CommitAction_label");
ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team",
menuString);
TestUtil.joinJobs(ADD_TO_INDEX);
TestUtil.waitUntilViewWithGivenIdShows(StagingView.VIEW_ID);
final Repository[] repo = { null };
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
StagingView view;
try {
view = (StagingView) PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage()
.showView(StagingView.VIEW_ID);
repo[0] = view.getCurrentRepository();
} catch (PartInitException e) {
// Ignore, repo[0] remains null
}
}
});
Repository repository = lookupRepository(repositoryFile);
assertNotNull("No repository found", repository);
assertEquals("Repository mismatch", repository, repo[0]);
}
@Test
public void testCommitWithoutAutoStage() throws Exception {
setTestFileContent("I have changed this");
SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
util.getProjectItems(projectExplorerTree, PROJ1)[0].select();
String menuString = util.getPluginLocalizedValue("CommitAction_label");
ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team",
menuString);
TestUtil.joinJobs(ADD_TO_INDEX);
TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
TestUtil.waitUntilViewWithGivenIdShows(StagingView.VIEW_ID);
StagingUtil.assertStaging(PROJ1, FOLDER + '/' + FILE1, false);
}
@Test
public void testCommitWithAutoStageNoUntracked() throws Exception {
assertCommitWithAutoStage(false);
}
@Test
public void testCommitWithAutoStageWithUntracked() throws Exception {
assertCommitWithAutoStage(true);
}
private void assertCommitWithAutoStage(boolean withUntracked)
throws Exception {
Activator.getDefault().getPreferenceStore()
.setValue(UIPreferences.AUTO_STAGE_ON_COMMIT, true);
boolean initialIncludeUntracked = Activator.getDefault()
.getPreferenceStore()
.getBoolean(UIPreferences.COMMIT_DIALOG_INCLUDE_UNTRACKED);
Activator.getDefault().getPreferenceStore().setValue(
UIPreferences.COMMIT_DIALOG_INCLUDE_UNTRACKED, withUntracked);
String newFile = "newFile.txt";
try {
setTestFileContent("I have changed this");
touch(PROJ1, newFile, "New file content");
SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
util.getProjectItems(projectExplorerTree, PROJ1)[0].select();
String menuString = util
.getPluginLocalizedValue("CommitAction_label");
JobJoiner joiner = JobJoiner.startListening(ADD_TO_INDEX, 10,
TimeUnit.SECONDS);
ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team",
menuString);
joiner.join();
TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
TestUtil.waitUntilViewWithGivenIdShows(StagingView.VIEW_ID);
StagingUtil.assertStaging(PROJ1, FOLDER + '/' + FILE1, true);
StagingUtil.assertStaging(PROJ1, newFile, withUntracked);
} finally {
Activator.getDefault().getPreferenceStore().setValue(
UIPreferences.COMMIT_DIALOG_INCLUDE_UNTRACKED,
initialIncludeUntracked);
}
}
}
|