use of com.oxygenxml.git.service.BranchInfo in project oxygen-git-client-addon by oxygenxml.
the class ToolbarPanel method updateButtonsStates.
/**
* Updates the presented information, like the Pull-behind, Pushes-ahead
* and branch status.
*/
public void updateButtonsStates() {
this.pullsBehind = GIT_ACCESS.getPullsBehind();
try {
this.pushesAhead = GIT_ACCESS.getPushesAhead();
} catch (RepoNotInitializedException e) {
this.pushesAhead = -1;
LOGGER.debug(e.getMessage(), e);
}
Repository repo = null;
try {
repo = GIT_ACCESS.getRepository();
} catch (NoRepositorySelected e) {
LOGGER.debug(e.getMessage(), e);
}
final Collection<RevCommit> stashes = GIT_ACCESS.listStashes();
if (stashes != null) {
noOfStashes = stashes.size();
}
final boolean isPullMenuEnabled = isPullButtonEnabled();
final boolean isStashButtonEnabled = isStashButtonEnabled();
SwingUtilities.invokeLater(() -> {
/* for @pushButton, @historyButton, @showBranchesButton --->
* it is necessary to refresh, even if it has a single action,
* because there are other code sequences that directly change their state by calling the setEnabled(false) method
*/
pushButton.setEnabled(gitActionsManager.getPushAction().isEnabled());
pullMenuButton.setEnabled(isPullMenuEnabled);
stashButton.setEnabled(isStashButtonEnabled);
historyButton.setEnabled(gitActionsManager.getShowHistoryAction().isEnabled());
showBranchesButton.setEnabled(gitActionsManager.getShowBranchesAction().isEnabled());
pullMenuButton.repaint();
pushButton.repaint();
stashButton.repaint();
});
BranchInfo branchInfo = GIT_ACCESS.getBranchInfo();
String currentBranchName = branchInfo.getBranchName();
if (branchInfo.isDetached()) {
SwingUtilities.invokeLater(() -> {
pushButton.setToolTipText(TRANSLATOR.getTranslation(Tags.PUSH_BUTTON_TOOLTIP));
pullMenuButton.setToolTipText(TRANSLATOR.getTranslation(Tags.PULL_BUTTON_TOOLTIP));
});
String tooltipText = TRANSLATOR.getTranslation(Tags.TOOLBAR_PANEL_INFORMATION_STATUS_DETACHED_HEAD) + " " + currentBranchName;
if (repo != null && repo.getRepositoryState() == RepositoryState.REBASING_MERGE) {
tooltipText += "<br>" + TRANSLATOR.getTranslation(Tags.REBASE_IN_PROGRESS) + ".";
}
tooltipText = TextFormatUtil.toHTML(tooltipText);
} else {
if (currentBranchName != null && !currentBranchName.isEmpty()) {
String upstreamBranchFromConfig = GIT_ACCESS.getUpstreamBranchShortNameFromConfig(currentBranchName);
boolean isAnUpstreamBranchDefinedInConfig = upstreamBranchFromConfig != null;
String upstreamShortestName = isAnUpstreamBranchDefinedInConfig ? upstreamBranchFromConfig.substring(upstreamBranchFromConfig.lastIndexOf('/') + 1) : null;
Ref remoteBranchRefForUpstreamFromConfig = isAnUpstreamBranchDefinedInConfig ? RepoUtil.getRemoteBranch(upstreamShortestName) : null;
boolean existsRemoteBranchForUpstreamDefinedInConfig = remoteBranchRefForUpstreamFromConfig != null;
String commitsBehindMessage = "";
String commitsAheadMessage = "";
if (isAnUpstreamBranchDefinedInConfig && existsRemoteBranchForUpstreamDefinedInConfig) {
if (pullsBehind == 0) {
commitsBehindMessage = TRANSLATOR.getTranslation(Tags.TOOLBAR_PANEL_INFORMATION_STATUS_UP_TO_DATE);
} else if (pullsBehind == 1) {
commitsBehindMessage = TRANSLATOR.getTranslation(Tags.ONE_COMMIT_BEHIND);
} else {
commitsBehindMessage = MessageFormat.format(TRANSLATOR.getTranslation(Tags.COMMITS_BEHIND), pullsBehind);
}
if (pushesAhead == 0) {
commitsAheadMessage = TRANSLATOR.getTranslation(Tags.NOTHING_TO_PUSH);
} else if (pushesAhead == 1) {
commitsAheadMessage = TRANSLATOR.getTranslation(Tags.ONE_COMMIT_AHEAD);
} else {
commitsAheadMessage = MessageFormat.format(TRANSLATOR.getTranslation(Tags.COMMITS_AHEAD), pushesAhead);
}
}
// ===================== Push button tooltip =====================
String pushButtonTooltipFinal = updatePushToolTip(isAnUpstreamBranchDefinedInConfig, existsRemoteBranchForUpstreamDefinedInConfig, upstreamBranchFromConfig, commitsAheadMessage, currentBranchName, repo);
SwingUtilities.invokeLater(() -> pushButton.setToolTipText(pushButtonTooltipFinal));
// ===================== Pull button tooltip =====================
String pullButtonTooltipFinal = updatePullToolTip(isAnUpstreamBranchDefinedInConfig, existsRemoteBranchForUpstreamDefinedInConfig, upstreamBranchFromConfig, commitsBehindMessage, remoteBranchRefForUpstreamFromConfig, repo);
SwingUtilities.invokeLater(() -> pullMenuButton.setToolTipText(pullButtonTooltipFinal));
}
}
}
use of com.oxygenxml.git.service.BranchInfo in project oxygen-git-client-addon by oxygenxml.
the class BranchSelectionCombo method refresh.
/**
* Refresh.
*/
public void refresh() {
int pullsBehind = GIT_ACCESS.getPullsBehind();
int pushesAhead = -1;
try {
pushesAhead = GIT_ACCESS.getPushesAhead();
} catch (RepoNotInitializedException e) {
LOGGER.debug(e.getMessage(), e);
}
// update pop up
updateBranchesPopup();
Repository repo = null;
try {
repo = GIT_ACCESS.getRepository();
} catch (NoRepositorySelected e) {
LOGGER.debug(e.getMessage(), e);
}
this.setEnabled(repo != null);
final BranchInfo branchInfo = GIT_ACCESS.getBranchInfo();
final String currentBranchName = branchInfo.getBranchName();
if (branchInfo.isDetached()) {
detachedHeadId = currentBranchName;
String tooltipText = TRANSLATOR.getTranslation(Tags.TOOLBAR_PANEL_INFORMATION_STATUS_DETACHED_HEAD) + " " + currentBranchName;
if (repo != null && repo.getRepositoryState() == RepositoryState.REBASING_MERGE) {
tooltipText += "<br>" + TRANSLATOR.getTranslation(Tags.REBASE_IN_PROGRESS) + ".";
}
tooltipText = TextFormatUtil.toHTML(tooltipText);
String finalText = tooltipText;
SwingUtilities.invokeLater(() -> this.setToolTipText(finalText));
} else {
detachedHeadId = null;
String branchTooltip = null;
if (currentBranchName != null && !currentBranchName.isEmpty()) {
branchTooltip = getBranchTooltip(pullsBehind, pushesAhead, currentBranchName);
}
String branchTooltipFinal = branchTooltip;
this.setToolTipText(branchTooltipFinal);
}
}
use of com.oxygenxml.git.service.BranchInfo in project oxygen-git-client-addon by oxygenxml.
the class BranchSelectionCombo method treatBranchSelectedEvent.
/**
* Treat a branch name selection event.
*
* @param event The event to treat.
*/
private void treatBranchSelectedEvent(final ItemEvent event) {
final String branchName = (String) event.getItem();
final BranchInfo currentBranchInfo = GIT_ACCESS.getBranchInfo();
final String currentBranchName = currentBranchInfo.getBranchName();
if (branchName.equals(currentBranchName)) {
return;
}
final RepositoryState repoState = RepoUtil.getRepoState().orElse(null);
if (RepoUtil.isNonConflictualRepoWithUncommittedChanges(repoState)) {
SwingUtilities.invokeLater(() -> {
BranchSwitchConfirmationDialog dialog = new BranchSwitchConfirmationDialog(branchName);
dialog.setVisible(true);
int answer = dialog.getResult();
if (answer == OKOtherAndCancelDialog.RESULT_OTHER) {
tryCheckingOutBranch(currentBranchInfo, branchName);
} else if (answer == OKOtherAndCancelDialog.RESULT_OK) {
boolean wasStashCreated = StashUtil.stashChanges();
if (wasStashCreated) {
tryCheckingOutBranch(currentBranchInfo, branchName);
}
} else {
restoreCurrentBranchSelectionInMenu();
}
});
} else {
tryCheckingOutBranch(currentBranchInfo, branchName);
}
}
use of com.oxygenxml.git.service.BranchInfo in project oxygen-git-client-addon by oxygenxml.
the class GitEditorVariables2Test method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
noOfShortBranchCalls = 0;
noOfFullBranchCalls = 0;
noOfWCCalls = 0;
Repository repo = createRepository(LOCAL_TEST_REPOSITORY);
GitAccess.getInstance().setRepositorySynchronously(LOCAL_TEST_REPOSITORY);
GitAccess gitAccessMock = Mockito.mock(GitAccess.class);
Mockito.doAnswer(new Answer<BranchInfo>() {
@Override
public BranchInfo answer(InvocationOnMock invocation) throws Throwable {
noOfShortBranchCalls++;
return new BranchInfo("main", false);
}
}).when(gitAccessMock).getBranchInfo();
Mockito.doAnswer(new Answer<Repository>() {
@Override
public Repository answer(InvocationOnMock invocation) throws Throwable {
noOfFullBranchCalls++;
return repo;
}
}).when(gitAccessMock).getRepository();
Mockito.doAnswer(new Answer<File>() {
@Override
public File answer(InvocationOnMock invocation) throws Throwable {
noOfWCCalls++;
return new File(LOCAL_TEST_REPOSITORY);
}
}).when(gitAccessMock).getWorkingCopy();
editorVariablesResolver = new GitEditorVariablesResolver(new GitController(gitAccessMock));
}
Aggregations