private static boolean pushCurrentBranch(@NotNull Project project, @NotNull GitRepository repository, @NotNull String remoteName, @NotNull String remoteUrl, @NotNull String name, @NotNull String url) { Git git = ServiceManager.getService(Git.class); GitLocalBranch currentBranch = repository.getCurrentBranch(); if (currentBranch == null) { showErrorDialog(project, "Project was create on GitLAb server, but cannot be pushed.", "Cannot Be Pushed"); return false; } GitCommandResult result = git.push(repository, remoteName, remoteUrl, currentBranch.getName(), true); if (!result.success()) { showErrorDialog(project, "Project was create on GitLab server, but cannot be pushed.", "Cannot Be Pushed"); return false; } return true; } }
public static GitLocalBranch createLocalBranch(final String name) { GitLocalBranch branch = mock(GitLocalBranch.class); when(branch.getName()).thenReturn(name); when(branch.getFullName()).thenReturn(name); when(branch.isRemote()).thenReturn(false); return branch; }
private void diffChange(Project project, ChangeInfo changeInfo) { Optional<GitRepository> gitRepositoryOptional = gerritGitUtil.getRepositoryForGerritProject(project, changeInfo.project); if (!gitRepositoryOptional.isPresent()) { NotificationBuilder notification = new NotificationBuilder(project, "Error", String.format("No repository found for Gerrit project: '%s'.", changeInfo.project)); notificationService.notifyError(notification); return; } GitRepository gitRepository = gitRepositoryOptional.get(); final String branchName = "FETCH_HEAD"; GitLocalBranch currentBranch = gitRepository.getCurrentBranch(); final String currentBranchName; if (currentBranch != null) { currentBranchName = currentBranch.getFullName(); } else { currentBranchName = gitRepository.getCurrentRevision(); } assert currentBranchName != null : "Current branch is neither a named branch nor a revision"; GitCommitCompareInfo compareInfo = gerritGitUtil.loadCommitsToCompare( Collections.singletonList(gitRepository), branchName, project); new GitCompareBranchesDialog(project, branchName, currentBranchName, compareInfo, gitRepository).show(); }
@Override public void run(@NotNull ProgressIndicator indicator) { if(title.startsWith("WIP:")) { projectState.setMergeAsWorkInProgress(true); } else { projectState.setMergeAsWorkInProgress(false); } projectState.setDeleteMergedBranch(removeSourceBranch); indicator.setText("Pushing current branch..."); GitCommandResult result = git.push(gitRepository, branch.getRemoteName(), remoteUrl, gitLocalBranch.getName(), true); if (!result.success()) { showErrorDialog(project, "Push failed:<br/>" + result.getErrorOutputAsHtmlString(), CANNOT_CREATE_MERGE_REQUEST); return; } indicator.setText("Creating merge request..."); GitlabMergeRequest mergeRequest; try { mergeRequest = settingsState.api(gitRepository).createMergeRequest(gitlabProject, assignee, gitLocalBranch.getName(), branch.getName(), title, description, removeSourceBranch); } catch (IOException e) { showErrorDialog(project, "Cannot create Merge Request via GitLab REST API", CANNOT_CREATE_MERGE_REQUEST); return; } VcsNotifier.getInstance(project) .notifyImportantInfo(title, "<a href='" + generateMergeRequestUrl(settingsState.currentGitlabServer(gitRepository), mergeRequest) + "'>Merge request '" + title + "' created</a>", NotificationListener.URL_OPENING_LISTENER); } }.queue();
git.push(repository, remoteName, remoteUrl, currentBranch.getName(), true); if (!result.success()) { LOG.warn(result.getErrorOutputAsJoinedString());
String localBranchName = "'" + gitLocalBranch.getName() + "'"; String targetBranchName = "'" + branch.getRemoteName() + "/" + branch.getName() + "'"; if (info.getInfo().getBranchToHeadCommits(gitRepository).isEmpty()) {
assigneeBox.setBounds(140, 170, 180, 20); currentBranch.setText(mergeRequestWorker.getGitLocalBranch().getName());
originalBranchName = sourceRepository.getCurrentBranch().getName(); } else { originalBranchName = sourceRepository.getCurrentRevision();
mergeRequestWorker.setLocalBranchInfo(new BranchInfo(mergeRequestWorker.getGitLocalBranch().getName(), mergeRequestWorker.getRemoteProjectName(), false)); mergeRequestWorker.setSearchableUsers(new SearchableUsers(project, file, mergeRequestWorker.getGitlabProject()));