use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class GitHistoryUtilsTest method testGetLastRevisionForExistingFile.
@Test(enabled = false)
public void testGetLastRevisionForExistingFile() throws Exception {
final ItemLatestState state = GitHistoryUtils.getLastRevision(myProject, toFilePath(bfile));
assertTrue(state.isItemExists());
final GitRevisionNumber revisionNumber = (GitRevisionNumber) state.getNumber();
assertEquals(revisionNumber.getRev(), myRevisions.get(0).myHash);
assertEquals(revisionNumber.getTimestamp(), myRevisions.get(0).myDate);
}
use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class GithubOpenInBrowserAction method getCurrentFileRevisionHash.
@Nullable
private static String getCurrentFileRevisionHash(@NotNull final Project project, @NotNull final VirtualFile file) {
final Ref<GitRevisionNumber> ref = new Ref<>();
ProgressManager.getInstance().run(new Task.Modal(project, "Getting Last Revision", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
ref.set((GitRevisionNumber) GitHistoryUtils.getCurrentRevision(project, VcsUtil.getFilePath(file), "HEAD"));
} catch (VcsException e) {
LOG.warn(e);
}
}
@Override
public void onCancel() {
throw new ProcessCanceledException();
}
});
if (ref.isNull())
return null;
return ref.get().getRev();
}
use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class GitCompareWithBranchAction method getDiffChanges.
@Override
@NotNull
protected Collection<Change> getDiffChanges(@NotNull Project project, @NotNull VirtualFile file, @NotNull String branchToCompare) throws VcsException {
FilePath filePath = VcsUtil.getFilePath(file);
final GitRepository gitRepository = GitUtil.getRepositoryManager(project).getRepositoryForFile(file);
if (gitRepository == null) {
throw new VcsException("Couldn't find Git Repository for " + file.getName());
}
final VirtualFile gitRepositoryRoot = gitRepository.getRoot();
GitRevisionNumber compareRevisionNumber = new GitRevisionNumber(branchToCompare);
Collection<Change> changes = GitChangeUtils.getDiffWithWorkingDir(project, gitRepositoryRoot, branchToCompare, Collections.singletonList(filePath), false);
// a.e. when you perform compareWith for unversioned file
if (changes.isEmpty() && GitHistoryUtils.getCurrentRevision(project, filePath, branchToCompare) == null) {
throw new VcsException(fileDoesntExistInBranchError(file, branchToCompare));
}
return changes.isEmpty() && !filePath.isDirectory() ? createChangesWithCurrentContentForFile(filePath, GitContentRevision.createRevision(filePath, compareRevisionNumber, project, null)) : changes;
}
use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class GitMergeAction method perform.
protected void perform(@NotNull final Project project, @NotNull final List<VirtualFile> gitRoots, @NotNull final VirtualFile defaultRoot) {
final DialogState dialogState = displayDialog(project, gitRoots, defaultRoot);
if (dialogState == null) {
return;
}
final VirtualFile selectedRoot = dialogState.selectedRoot;
final Computable<GitLineHandler> handlerProvider = dialogState.handlerProvider;
final Label beforeLabel = LocalHistory.getInstance().putSystemLabel(project, "Before update");
new Task.Backgroundable(project, dialogState.progressTitle, true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
final GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(project);
final Git git = Git.getInstance();
final GitLocalChangesWouldBeOverwrittenDetector localChangesDetector = new GitLocalChangesWouldBeOverwrittenDetector(selectedRoot, MERGE);
final GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector = new GitUntrackedFilesOverwrittenByOperationDetector(selectedRoot);
final GitSimpleEventDetector mergeConflict = new GitSimpleEventDetector(GitSimpleEventDetector.Event.MERGE_CONFLICT);
AccessToken token = DvcsUtil.workingTreeChangeStarted(project);
try {
GitCommandResult result = git.runCommand(() -> {
GitLineHandler handler = handlerProvider.compute();
handler.addLineListener(localChangesDetector);
handler.addLineListener(untrackedFilesDetector);
handler.addLineListener(mergeConflict);
return handler;
});
GitRepository repository = repositoryManager.getRepositoryForRoot(selectedRoot);
assert repository != null : "Repository can't be null for root " + selectedRoot;
String revision = repository.getCurrentRevision();
if (revision == null) {
return;
}
final GitRevisionNumber currentRev = new GitRevisionNumber(revision);
handleResult(result, project, mergeConflict, localChangesDetector, untrackedFilesDetector, repository, currentRev, beforeLabel);
} finally {
token.finish();
}
}
}.queue();
}
use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class GitChangeUtils method parseChangeList.
/**
* Parse changelist
*
*
*
* @param project the project
* @param root the git root
* @param s the scanner for log or show command output
* @param skipDiffsForMerge
* @param handler the handler that produced the output to parse. - for debugging purposes.
* @param local pass {@code true} to indicate that this revision should be an editable
* {@link com.intellij.openapi.vcs.changes.CurrentContentRevision}.
* Pass {@code false} for
* @param revertable
* @return the parsed changelist
* @throws VcsException if there is a problem with running git
*/
public static GitCommittedChangeList parseChangeList(Project project, VirtualFile root, StringScanner s, boolean skipDiffsForMerge, GitHandler handler, boolean local, boolean revertable) throws VcsException {
ArrayList<Change> changes = new ArrayList<>();
// parse commit information
final Date commitDate = GitUtil.parseTimestampWithNFEReport(s.line(), handler, s.getAllText());
final String revisionNumber = s.line();
final String parentsLine = s.line();
final String[] parents = parentsLine.length() == 0 ? ArrayUtil.EMPTY_STRING_ARRAY : parentsLine.split(" ");
String authorName = s.line();
String committerName = s.line();
committerName = GitUtil.adjustAuthorName(authorName, committerName);
String commentSubject = s.boundedToken('', true);
s.nextLine();
String commentBody = s.boundedToken('', true);
// construct full comment
String fullComment;
if (commentSubject.length() == 0) {
fullComment = commentBody;
} else if (commentBody.length() == 0) {
fullComment = commentSubject;
} else {
fullComment = commentSubject + "\n" + commentBody;
}
GitRevisionNumber thisRevision = new GitRevisionNumber(revisionNumber, commitDate);
if (skipDiffsForMerge || (parents.length <= 1)) {
final GitRevisionNumber parentRevision = parents.length > 0 ? resolveReference(project, root, parents[0]) : null;
// This is the first or normal commit with the single parent.
// Just parse changes in this commit as returned by the show command.
parseChanges(project, root, thisRevision, local ? null : parentRevision, s, changes, null);
} else {
for (String parent : parents) {
final GitRevisionNumber parentRevision = resolveReference(project, root, parent);
GitSimpleHandler diffHandler = new GitSimpleHandler(project, root, GitCommand.DIFF);
diffHandler.setSilent(true);
diffHandler.addParameters("--name-status", "-M", parentRevision.getRev(), thisRevision.getRev());
String diff = diffHandler.run();
parseChanges(project, root, thisRevision, parentRevision, diff, changes, null);
if (changes.size() > 0) {
break;
}
}
}
String changeListName = String.format("%s(%s)", commentSubject, revisionNumber);
return new GitCommittedChangeList(changeListName, fullComment, committerName, thisRevision, commitDate, changes, assertNotNull(GitVcs.getInstance(project)), revertable);
}
Aggregations