@NotNull public Pair<List<GitCommit>, List<GitCommit>> loadCommitsToCompare(@NotNull GitRepository repository, @NotNull final String branchName, @NotNull final Project project) { final List<GitCommit> headToBranch; final List<GitCommit> branchToHead; try { headToBranch = GitHistoryUtils.history(project, repository.getRoot(), ".." + branchName); branchToHead = GitHistoryUtils.history(project, repository.getRoot(), branchName + ".."); } catch (VcsException e) { // we treat it as critical and report an error throw new GitExecutionException("Couldn't get [git log .." + branchName + "] on repository [" + repository.getRoot() + "]", e); } return Pair.create(headToBranch, branchToHead); }
public String getRelativePath(Project project, String absoluteFilePath, String gerritProjectName) { Optional<GitRepository> gitRepositoryOptional = gerritGitUtil.getRepositoryForGerritProject(project, gerritProjectName); if (!gitRepositoryOptional.isPresent()) return null; GitRepository repository = gitRepositoryOptional.get(); VirtualFile root = repository.getRoot(); return FileUtil.getRelativePath(new File(root.getPath()), new File(absoluteFilePath)); }
@NotNull private DiffInfo doLoadDiffInfo(@NotNull final BranchInfo from, @NotNull final BranchInfo to) throws VcsException { String currentBranch = from.getFullName(); String targetBranch = to.getFullRemoteName(); List<GitCommit> commits1 = GitHistoryUtils.history(project, gitRepository.getRoot(), ".." + targetBranch); List<GitCommit> commits2 = GitHistoryUtils.history(project, gitRepository.getRoot(), targetBranch + ".."); Collection<Change> diff = GitChangeUtils.getDiff(project, gitRepository.getRoot(), targetBranch, currentBranch, null); GitCommitCompareInfo info = new GitCommitCompareInfo(GitCommitCompareInfo.InfoType.BRANCH_TO_HEAD); info.put(gitRepository, diff); info.put(gitRepository, Couple.of(commits1, commits2)); return new DiffInfo(info, currentBranch, targetBranch); }
@Before public void startUp() { Mockito.when(mockGitRepository.getRoot()).thenReturn(mockVirtualFile); }
/** Refresh the repository files. */ @SuppressWarnings("ConstantConditions") public void hardRefresh() { if (repoState.hasSourceRepository()) { List<VirtualFile> list = VfsUtil.markDirty(true, true, repoState.getSourceRepository().getRoot()); if (!list.isEmpty()) { LocalFileSystem.getInstance().refreshFiles(list, false, true, null); } } }
private static void removeGitRemote( final @NotNull Project project, @NotNull GitRepository repository, @NotNull String remote) { final GitSimpleHandler handler = new GitSimpleHandler(project, repository.getRoot(), GitCommand.REMOTE); handler.setSilent(true); try { handler.addParameters("remove", remote); handler.run(); } catch (final VcsException ex) { LOG.error("error removing newly added remote on error:" + ex.toString()); } // catch newly added remote repository.update(); }
@Before public void setUp() throws Exception { gitUtilWrapperMock = Mockito.mock(DiffCompareInfoProvider.GitUtilWrapper.class); projectMock = Mockito.mock(Project.class); gitRepositoryMock = Mockito.mock(GitRepository.class); fileMock = Mockito.mock(VirtualFile.class); when(gitRepositoryMock.getRoot()).thenReturn(fileMock); underTest = new DiffCompareInfoProvider(); underTest.setUtilWrapper(gitUtilWrapperMock); }
public static boolean addGitLabRemote(@NotNull Project project, @NotNull GitRepository repository, @NotNull String remote, @NotNull String url) { final GitSimpleHandler handler = new GitSimpleHandler(project, repository.getRoot(), GitCommand.REMOTE); handler.setSilent(true); try { handler.addParameters("add", remote, url); handler.run(); if (handler.getExitCode() != 0) { showErrorDialog(project, "New remote origin cannot be added to this project.", "Cannot Add New Remote"); return false; } // catch newly added remote repository.update(); return true; } catch (VcsException e) { showErrorDialog(project, "New remote origin cannot be added to this project.", "Cannot Add New Remote"); return false; } }
@Override public void run(@NotNull ProgressIndicator indicator) { GitRemote remote; String fetch; String url; boolean commitIsFetched = checkIfCommitIsFetched(gitRepository, commitHash); if (commitIsFetched) { // 'git fetch' works with a local path instead of a remote -> this way FETCH_HEAD is set remote = new GitRemote(gitRepository.getRoot().getPath(), Collections.<String>emptyList(), Collections.<String>emptySet(), Collections.<String>emptyList(), Collections.<String>emptyList()); fetch = commitHash; url = ""; } else { remote = getRemoteForChange(project, gitRepository, fetchInfo).orNull(); if (remote == null) { return; } fetch = fetchInfo.ref; url = remote.getFirstUrl(); } GitFetchResult result = fetchNatively(gitRepository.getGitDir(), remote, url, fetch, project, indicator); if (!result.isSuccess()) { GitFetcher.displayFetchResult(project, result, null, result.getErrors()); } } });
private boolean doFetchRemote(@NotNull BranchInfo branch) { if (branch.getName() == null) { return false; } GitFetchResult result = new GitFetcher(project, new EmptyProgressIndicator(), false).fetch(gitRepository.getRoot(), branch.getRemoteName(), null); if (!result.isSuccess()) { GitFetcher.displayFetchResult(project, result, null, result.getErrors()); return false; } return true; }
public boolean checkIfCommitIsFetched(GitRepository repository, String commitHash) { FormattedGitLineHandlerListener listener = new FormattedGitLineHandlerListener(); final GitLineHandler h = new GitLineHandler(repository.getProject(), repository.getRoot(), GitCommand.SHOW); h.setSilent(false); h.setStdoutSuppressed(false); h.addParameters(commitHash); h.addParameters("--format=short"); h.endOptions(); h.addLineListener(listener); GitCommandResult gitCommandResult = git.runCommand(new Computable<GitLineHandler>() { @Override public GitLineHandler compute() { return h; } }); boolean success = gitCommandResult.success(); List<String> output = gitCommandResult.getOutput(); boolean isCommit = !output.isEmpty() && output.get(0).startsWith("commit"); return success && isCommit; }
GitSimpleEventDetector localChangesOverwrittenDetector = new GitSimpleEventDetector(LOCAL_CHANGES_OVERWRITTEN_BY_CHERRY_PICK); GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector = new GitUntrackedFilesOverwrittenByOperationDetector(repository.getRoot()); GitCommandResult result = git.cherryPick(repository, commit.getId().asString(), false, conflictDetector, localChangesOverwrittenDetector, untrackedFilesDetector); return true; } else if (conflictDetector.hasHappened()) { return new CherryPickConflictResolver(project, git, platformFacade, repository.getRoot(), commit.getId().toShortString(), commit.getAuthor().getName(), commit.getSubject()).merge(); "Please move, remove or add them before you can cherry-pick. <a href='view'>View them</a>"; UntrackedFilesNotifier.notifyUntrackedFilesOverwrittenBy(project, repository.getRoot(), untrackedFilesDetector.getRelativeFilePaths(), "cherry-pick", description);
final @NotNull String url) { final GitSimpleHandler handler = new GitSimpleHandler(project, repository.getRoot(), GitCommand.REMOTE); handler.setSilent(true); try {
private boolean stash() { if (!syncResult.hasLocalRepository()) { LOG.error("unexpected null local repro in call to stash"); return false; } final ChangeListManager changeListManager = ChangeListManager.getInstance(project); if (changeListManager.isFreezedWithNotification("Can not stash changes now")) { return false; } final GitLineHandler handler = new GitLineHandler(project, sourceRepository.getRoot(), GitCommand.STASH); handler.addParameters("save"); handler.addParameters("--keep-index"); String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date()); stashMessage = "Cloud Debugger saved changes from branch " + originalBranchName + " at " + date; handler.addParameters(stashMessage); AccessToken token = DvcsUtil.workingTreeChangeStarted(project); try { GitHandlerUtil.doSynchronously( handler, GitBundle.getString("stashing.title"), handler.printableCommandLine()); } finally { token.finish(); } return true; }
final VirtualFile root = gitDetected ? gitRepository.getRoot() : project.getBaseDir();
final Collection<Change> totalDiff; try { VirtualFile gitRepositoryRoot = gitRepository.getRoot(); CommitDiffBuilder.ChangesProvider changesProvider = new ChangesWithCommitMessageProvider(); GitCommit currentCommit = getCommit(gitRepositoryRoot, revisionId);
if (repoState.hasSourceRepository()) { assert repoState.getSourceRepository() != null; final VirtualFile root = repoState.getSourceRepository().getRoot();
public void setUpstreamBranch(GitRepository repository, String remoteBranch) throws VcsException { FormattedGitLineHandlerListener listener = new FormattedGitLineHandlerListener(); final GitLineHandler h = new GitLineHandler(repository.getProject(), repository.getRoot(), GitCommand.BRANCH); h.setSilent(false); h.setStdoutSuppressed(false); h.addParameters("-u", "remotes/" + remoteBranch); h.endOptions(); h.addLineListener(listener); GitCommandResult gitCommandResult = git.runCommand(new Computable<GitLineHandler>() { @Override public GitLineHandler compute() { return h; } }); if (!gitCommandResult.success()) { throw new VcsException(listener.getHtmlMessage()); } }
try { GitChangeUtils.resolveReference( processState.getProject(), repository.getRoot(), revisionId); targetLocalRepo = repository; break; if (GitUtil.hasLocalChanges(true, processState.getProject(), targetLocalRepo.getRoot()) || GitUtil.hasLocalChanges( false, processState.getProject(), targetLocalRepo.getRoot())) { needsStash = true;
final VirtualFile root = gitDetected ? gitRepository.getRoot() : project.getBaseDir();