1 /*******************************************************************************
2 * Copyright (C) 2012, 2013 Robin Stocker <robin@nibor.org>
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
10 *******************************************************************************/
11 package org
.eclipse
.egit
.ui
.view
.synchronize
;
13 import static org
.hamcrest
.Matchers
.is
;
14 import static org
.junit
.Assert
.assertThat
;
16 import java
.util
.concurrent
.TimeUnit
;
18 import org
.eclipse
.egit
.core
.op
.FetchOperation
;
19 import org
.eclipse
.egit
.ui
.JobFamilies
;
20 import org
.eclipse
.egit
.ui
.internal
.UIText
;
21 import org
.eclipse
.egit
.ui
.test
.JobJoiner
;
22 import org
.eclipse
.egit
.ui
.test
.TestUtil
;
23 import org
.eclipse
.jgit
.lib
.ConfigConstants
;
24 import org
.eclipse
.jgit
.lib
.Constants
;
25 import org
.eclipse
.jgit
.lib
.ObjectId
;
26 import org
.eclipse
.jgit
.lib
.Repository
;
27 import org
.eclipse
.jgit
.lib
.StoredConfig
;
28 import org
.eclipse
.jgit
.transport
.RefSpec
;
29 import org
.eclipse
.jgit
.transport
.RemoteConfig
;
30 import org
.eclipse
.jgit
.transport
.URIish
;
31 import org
.eclipse
.osgi
.util
.NLS
;
32 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
33 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotShell
;
34 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotToolbarButton
;
35 import org
.eclipse
.team
.ui
.synchronize
.ISynchronizeView
;
36 import org
.junit
.Before
;
37 import org
.junit
.Test
;
40 * Test for "Push" action in Synchronize view.
42 public class SynchronizeViewPushTest
extends AbstractSynchronizeViewTest
{
45 public void prepare() throws Exception
{
46 Repository childRepository
= lookupRepository(childRepositoryFile
);
48 Repository repository
= lookupRepository(repositoryFile
);
49 StoredConfig config
= repository
.getConfig();
50 RemoteConfig remoteConfig
= new RemoteConfig(config
, "origin");
51 remoteConfig
.addURI(new URIish(childRepository
.getDirectory().getParentFile().toURI().toURL()));
52 remoteConfig
.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
53 remoteConfig
.update(config
);
55 config
.setString(ConfigConstants
.CONFIG_BRANCH_SECTION
, "master", ConfigConstants
.CONFIG_KEY_REMOTE
, "origin");
56 config
.setString(ConfigConstants
.CONFIG_BRANCH_SECTION
, "master", ConfigConstants
.CONFIG_KEY_MERGE
, "refs/heads/master");
59 FetchOperation fetchOperation
= new FetchOperation(repository
, remoteConfig
, 60, false);
60 fetchOperation
.run(null);
64 public void shouldUpdateTrackingBranchOnPush() throws Exception
{
65 makeChangesAndCommit(PROJ1
);
66 Repository repository
= lookupRepository(repositoryFile
);
67 ObjectId headId
= repository
.resolve(Constants
.HEAD
);
69 String trackingBranch
= Constants
.R_REMOTES
+ "origin/master";
70 launchSynchronization(Constants
.HEAD
, trackingBranch
, false);
72 SWTBotView viewBot
= bot
.viewById(ISynchronizeView
.VIEW_ID
);
73 SWTBotToolbarButton pushButton
= viewBot
.toolbarButton(UIText
.GitActionContributor_Push
);
74 JobJoiner jobJoiner
= JobJoiner
.startListening(JobFamilies
.PUSH
, 30, TimeUnit
.SECONDS
);
76 TestUtil
.openJobResultDialog(jobJoiner
.join());
78 String destinationString
= repositoryFile
.getParentFile().getName() + " - " + "origin";
79 SWTBotShell resultDialog
= bot
.shell(NLS
.bind(UIText
.PushResultDialog_title
, destinationString
));
82 Repository remoteRepository
= lookupRepository(childRepositoryFile
);
83 ObjectId masterOnRemote
= remoteRepository
.resolve("master");
84 assertThat("Expected push to update branch on remote repository", masterOnRemote
, is(headId
));
86 ObjectId trackingId
= repository
.resolve(trackingBranch
);
87 assertThat("Expected tracking branch to be updated", trackingId
, is(headId
));