use of com.oxygenxml.git.view.event.BranchGitEventInfo in project oxygen-git-client-addon by oxygenxml.
the class GitAccess method checkoutRemoteBranchWithNewName.
/**
* Creates a local branch for a remote branch (which it starts tracking), and sets it as the current branch.
*
* @param newBranchName The name of the new branch created at checkout.
* @param remoteBranchName The branch to checkout (short name).
* @throws GitAPIException
*/
public void checkoutRemoteBranchWithNewName(String newBranchName, String remoteBranchName, String... remote) throws GitAPIException {
fireOperationAboutToStart(new BranchGitEventInfo(GitOperation.CHECKOUT, newBranchName));
String remoteString = remote.length == 0 ? Constants.DEFAULT_REMOTE_NAME : remote[0];
try {
git.checkout().setCreateBranch(true).setName(newBranchName).setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).setStartPoint(remoteString + "/" + remoteBranchName).call();
fireOperationSuccessfullyEnded(new BranchGitEventInfo(GitOperation.CHECKOUT, newBranchName));
} catch (GitAPIException e) {
fireOperationFailed(new BranchGitEventInfo(GitOperation.CHECKOUT, newBranchName), e);
throw e;
}
}
use of com.oxygenxml.git.view.event.BranchGitEventInfo in project oxygen-git-client-addon by oxygenxml.
the class GitAccess method deleteBranch.
/**
* Deletes from the current repository a local branch with a specified name.
* @param branchName The name of the branch to be deleted.
*/
public void deleteBranch(String branchName) {
DeleteBranchCommand command = git.branchDelete();
command.setBranchNames(branchName);
command.setForce(true);
try {
fireOperationAboutToStart(new BranchGitEventInfo(GitOperation.DELETE_BRANCH, branchName));
command.call();
fireOperationSuccessfullyEnded(new BranchGitEventInfo(GitOperation.DELETE_BRANCH, branchName));
} catch (GitAPIException e) {
fireOperationFailed(new BranchGitEventInfo(GitOperation.DELETE_BRANCH, branchName), e);
PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(e.getMessage(), e);
}
}
use of com.oxygenxml.git.view.event.BranchGitEventInfo in project oxygen-git-client-addon by oxygenxml.
the class GitAccess method internalMerge.
/**
* Merge the given branch into the current branch.
*
* @param branchName The full name of the branch to be merged into the current one(e.g. refs/heads/dev).
* @param isSquashMerge <code>true</code> if is a squash commit.
*
* @throws IOException
* @throws NoRepositorySelected
* @throws GitAPIException
*/
private void internalMerge(final String branchName, boolean isSquash) throws IOException, NoRepositorySelected, GitAPIException {
fireOperationAboutToStart(new BranchGitEventInfo(GitOperation.MERGE, branchName));
try {
final ObjectId mergeBase = getRepository().resolve(branchName);
final MergeCommand mergeCommand = git.merge().include(mergeBase);
if (isSquash) {
mergeCommand.setStrategy(MergeStrategy.RESOLVE).setSquash(isSquash).setCommit(true);
}
final MergeResult res = mergeCommand.call();
if (res.getMergeStatus().equals(MergeResult.MergeStatus.CONFLICTING)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("We have conflicts here: {}", res.getConflicts());
}
final List<String> conflictingFiles = new ArrayList<>(res.getConflicts().keySet());
FileStatusDialog.showWarningMessage(TRANSLATOR.getTranslation(Tags.MERGE_CONFLICTS_TITLE), conflictingFiles, TRANSLATOR.getTranslation(Tags.MERGE_CONFLICTS_MESSAGE));
} else if (res.getMergeStatus().equals(MergeResult.MergeStatus.FAILED)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Failed because of this files: {}", res.getFailingPaths());
}
final List<String> failingFiles = new ArrayList<>(res.getFailingPaths().keySet());
FileStatusDialog.showErrorMessage(TRANSLATOR.getTranslation(Tags.MERGE_FAILED_UNCOMMITTED_CHANGES_TITLE), failingFiles, TRANSLATOR.getTranslation(Tags.MERGE_FAILED_UNCOMMITTED_CHANGES_MESSAGE));
}
if (isSquash) {
final String squashMessage = getRepository().readSquashCommitMsg();
commit(squashMessage != null ? squashMessage : "");
}
fireOperationSuccessfullyEnded(new BranchGitEventInfo(GitOperation.MERGE, branchName));
} catch (RevisionSyntaxException | IOException | NoRepositorySelected e) {
fireOperationFailed(new BranchGitEventInfo(GitOperation.MERGE, branchName), e);
throw e;
} catch (CheckoutConflictException e) {
fireOperationFailed(new BranchGitEventInfo(GitOperation.MERGE, branchName), e);
FileStatusDialog.showWarningMessage(TRANSLATOR.getTranslation(Tags.MERGE_FAILED_UNCOMMITTED_CHANGES_TITLE), e.getConflictingPaths(), TRANSLATOR.getTranslation(Tags.MERGE_FAILED_UNCOMMITTED_CHANGES_MESSAGE));
}
}
use of com.oxygenxml.git.view.event.BranchGitEventInfo in project oxygen-git-client-addon by oxygenxml.
the class GitEditorVariables2Test method testCache.
/**
* <p><b>Description:</b> test Git editor variables cache.</p>
* <p><b>Bug ID:</b> EXM-46457</p>
*
* @author sorin_carbunaru
*
* @throws Exception
*/
public void testCache() throws Exception {
Map<String, String> cache = editorVariablesResolver.getEditorVarsCacheFromTests();
assertTrue(cache.isEmpty());
String resolved = editorVariablesResolver.resolveEditorVariables("bla", null);
assertEquals("bla", resolved);
assertTrue(cache.isEmpty());
// Short branch - git access should be called
resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.SHORT_BRANCH_NAME_EDITOR_VAR, null);
assertEquals("main", resolved);
assertEquals("{${git(short_branch_name)}=main}", cache.toString());
assertEquals(1, noOfShortBranchCalls);
// Short branch again - get it from cache
resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.SHORT_BRANCH_NAME_EDITOR_VAR, null);
assertEquals("main", resolved);
assertEquals("{${git(short_branch_name)}=main}", cache.toString());
assertEquals(1, noOfShortBranchCalls);
// Full branch name - git access should be called
resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.FULL_BRANCH_NAME_EDITOR_VAR, null);
assertEquals("refs/heads/main", resolved);
assertEquals(2, cache.size());
assertTrue(cache.toString().contains("${git(short_branch_name)}=main"));
assertTrue(cache.toString().contains("${git(full_branch_name)}=refs/heads/main"));
assertEquals(1, noOfFullBranchCalls);
// Full branch name again - get it from the cache
resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.FULL_BRANCH_NAME_EDITOR_VAR, null);
assertEquals("refs/heads/main", resolved);
assertEquals(2, cache.size());
assertTrue(cache.toString().contains("${git(short_branch_name)}=main"));
assertTrue(cache.toString().contains("${git(full_branch_name)}=refs/heads/main"));
assertEquals(1, noOfFullBranchCalls);
// WC name + WC path + WC URL - get them from git access, but request the WC only once
resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.WORKING_COPY_NAME_EDITOR_VAR + " " + GitEditorVariablesNames.WORKING_COPY_PATH_EDITOR_VAR + " " + GitEditorVariablesNames.WORKING_COPY_URL_EDITOR_VAR, null);
String expected = "EditorVariablesTest " + new File(LOCAL_TEST_REPOSITORY).getAbsolutePath() + " " + new File(LOCAL_TEST_REPOSITORY).toURI().toURL();
assertEquals(expected, resolved);
assertEquals(5, cache.size());
assertTrue(cache.toString().contains("${git(short_branch_name)}=main"));
assertTrue(cache.toString().contains("${git(full_branch_name)}=refs/heads/main"));
assertTrue(cache.toString().contains("${git(working_copy_name)}=EditorVariablesTest"));
assertTrue(cache.toString().contains("${git(working_copy_path)}=" + new File(LOCAL_TEST_REPOSITORY).getAbsolutePath()));
assertTrue(cache.toString().contains("${git(working_copy_url)}=" + new File(LOCAL_TEST_REPOSITORY).toURI().toURL().toString()));
assertEquals(1, noOfWCCalls);
// WC name + WC path + WC URL again- get them from git access
resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.WORKING_COPY_NAME_EDITOR_VAR, null);
assertEquals("EditorVariablesTest", resolved);
assertEquals(5, cache.size());
assertTrue(cache.toString().contains("${git(short_branch_name)}=main"));
assertTrue(cache.toString().contains("${git(full_branch_name)}=refs/heads/main"));
assertTrue(cache.toString().contains("${git(working_copy_name)}=EditorVariablesTest"));
assertTrue(cache.toString().contains("${git(working_copy_path)}=" + new File(LOCAL_TEST_REPOSITORY).getAbsolutePath()));
assertTrue(cache.toString().contains("${git(working_copy_url)}=" + new File(LOCAL_TEST_REPOSITORY).toURI().toURL().toString()));
assertEquals(1, noOfWCCalls);
// Simulate branch switch
editorVariablesResolver.getGitEventListenerFromTests().operationSuccessfullyEnded(new BranchGitEventInfo(GitOperation.CHECKOUT, ""));
assertEquals(3, cache.size());
assertTrue(cache.toString().contains("${git(working_copy_name)}=EditorVariablesTest"));
assertTrue(cache.toString().contains("${git(working_copy_path)}=" + new File(LOCAL_TEST_REPOSITORY).getAbsolutePath()));
assertTrue(cache.toString().contains("${git(working_copy_url)}=" + new File(LOCAL_TEST_REPOSITORY).toURI().toURL().toString()));
// Short + full branch name again - take them from git access
resolved = editorVariablesResolver.resolveEditorVariables(GitEditorVariablesNames.SHORT_BRANCH_NAME_EDITOR_VAR + " " + GitEditorVariablesNames.FULL_BRANCH_NAME_EDITOR_VAR, null);
assertEquals("main refs/heads/main", resolved);
assertEquals(5, cache.size());
assertTrue(cache.toString().contains("${git(short_branch_name)}=main"));
assertTrue(cache.toString().contains("${git(full_branch_name)}=refs/heads/main"));
assertTrue(cache.toString().contains("${git(working_copy_name)}=EditorVariablesTest"));
assertTrue(cache.toString().contains("${git(working_copy_path)}=" + new File(LOCAL_TEST_REPOSITORY).getAbsolutePath()));
assertTrue(cache.toString().contains("${git(working_copy_url)}=" + new File(LOCAL_TEST_REPOSITORY).toURI().toURL().toString()));
assertEquals(2, noOfShortBranchCalls);
assertEquals(2, noOfFullBranchCalls);
// Simulate repo switch
editorVariablesResolver.getGitEventListenerFromTests().operationSuccessfullyEnded(new WorkingCopyGitEventInfo(GitOperation.OPEN_WORKING_COPY, new File(".")));
assertTrue(cache.isEmpty());
}
Aggregations