use of git4idea.config.GitVersion in project intellij-community by JetBrains.
the class GitVersionTest method testParse.
/**
* Tests that parsing the 'git version' command output returns the correct GitVersion object.
* Tests on UNIX and on Windows - both CYGWIN and MSYS.
*/
@Test
public void testParse() throws Exception {
if (SystemInfo.isUnix) {
for (TestGitVersion test : commonTests) {
GitVersion version = GitVersion.parse(test.output);
assertEqualVersions(version, test, Type.UNIX);
}
} else if (SystemInfo.isWindows) {
for (TestGitVersion test : commonTests) {
GitVersion version = GitVersion.parse(test.output);
assertEqualVersions(version, test, Type.CYGWIN);
}
for (TestGitVersion test : msysTests) {
GitVersion version = GitVersion.parse(test.output);
assertEqualVersions(version, test, Type.MSYS);
}
}
}
use of git4idea.config.GitVersion in project intellij-community by JetBrains.
the class GitVersionTest method assertEqualVersions.
// Compares the parsed output and what we've expected.
// Uses reflection to get private fields of GitVersion: we don't need them in code, so no need to trash the class with unused accessors.
private static void assertEqualVersions(GitVersion actual, TestGitVersion expected, Type expectedType) throws Exception {
Field field = GitVersion.class.getDeclaredField("myMajor");
field.setAccessible(true);
final int major = field.getInt(actual);
field = GitVersion.class.getDeclaredField("myMinor");
field.setAccessible(true);
final int minor = field.getInt(actual);
field = GitVersion.class.getDeclaredField("myRevision");
field.setAccessible(true);
final int rev = field.getInt(actual);
field = GitVersion.class.getDeclaredField("myPatchLevel");
field.setAccessible(true);
final int patch = field.getInt(actual);
field = GitVersion.class.getDeclaredField("myType");
field.setAccessible(true);
final Type type = (Type) field.get(actual);
assertEquals(major, expected.major);
assertEquals(minor, expected.minor);
assertEquals(rev, expected.rev);
assertEquals(patch, expected.patch);
assertEquals(type, expectedType);
}
use of git4idea.config.GitVersion in project intellij-community by JetBrains.
the class GitVersionTest method testEqualsAndCompare.
@Test
public void testEqualsAndCompare() throws Exception {
GitVersion v1 = GitVersion.parse("git version 1.6.3");
GitVersion v2 = GitVersion.parse("git version 1.7.3");
GitVersion v3 = GitVersion.parse("git version 1.7.3");
GitVersion v4 = GitVersion.parse("git version 1.7.3.msysgit.0");
assertFalse(v1.equals(v2));
assertFalse(v1.equals(v3));
assertTrue(v2.equals(v3));
if (SystemInfo.isWindows) {
assertFalse(v1.equals(v4));
assertFalse(v2.equals(v4));
assertFalse(v3.equals(v4));
}
assertEquals(v1.compareTo(v2), -1);
assertEquals(v1.compareTo(v3), -1);
assertEquals(v1.compareTo(v4), -1);
assertEquals(v2.compareTo(v3), 0);
assertEquals(v2.compareTo(v4), 0);
assertEquals(v3.compareTo(v4), 0);
}
use of git4idea.config.GitVersion in project intellij-community by JetBrains.
the class GitChangeProvider method isNewGitChangeProviderAvailable.
private boolean isNewGitChangeProviderAvailable() {
GitVcs vcs = GitVcs.getInstance(myProject);
if (vcs == null) {
return false;
}
final GitVersion version = vcs.getVersion();
return GitVersionSpecialty.KNOWS_STATUS_PORCELAIN.existsIn(version);
}
use of git4idea.config.GitVersion in project intellij-community by JetBrains.
the class GitHistoryUtils method history.
public static void history(@NotNull Project project, @NotNull FilePath path, @Nullable VirtualFile root, @NotNull VcsRevisionNumber startingRevision, @NotNull Consumer<GitFileRevision> consumer, @NotNull Consumer<VcsException> exceptionConsumer, String... parameters) {
// adjust path using change manager
final FilePath filePath = getLastCommitName(project, path);
final VirtualFile finalRoot;
try {
finalRoot = (root == null ? GitUtil.getGitRoot(filePath) : root);
} catch (VcsException e) {
exceptionConsumer.consume(e);
return;
}
final GitLogParser logParser = new GitLogParser(project, GitLogParser.NameStatus.STATUS, HASH, COMMIT_TIME, AUTHOR_NAME, AUTHOR_EMAIL, COMMITTER_NAME, COMMITTER_EMAIL, PARENTS, SUBJECT, BODY, RAW_BODY, AUTHOR_TIME);
final AtomicReference<String> firstCommit = new AtomicReference<>(startingRevision.asString());
final AtomicReference<String> firstCommitParent = new AtomicReference<>(firstCommit.get());
final AtomicReference<FilePath> currentPath = new AtomicReference<>(filePath);
final AtomicReference<GitLineHandler> logHandler = new AtomicReference<>();
final AtomicBoolean skipFurtherOutput = new AtomicBoolean();
final Consumer<GitLogRecord> resultAdapter = record -> {
if (skipFurtherOutput.get()) {
return;
}
if (record == null) {
exceptionConsumer.consume(new VcsException("revision details are null."));
return;
}
record.setUsedHandler(logHandler.get());
final GitRevisionNumber revision = new GitRevisionNumber(record.getHash(), record.getDate());
firstCommit.set(record.getHash());
final String[] parentHashes = record.getParentsHashes();
if (parentHashes.length < 1) {
firstCommitParent.set(null);
} else {
firstCommitParent.set(parentHashes[0]);
}
final String message = record.getFullMessage();
FilePath revisionPath;
try {
final List<FilePath> paths = record.getFilePaths(finalRoot);
if (paths.size() > 0) {
revisionPath = paths.get(0);
} else {
revisionPath = currentPath.get();
}
Couple<String> authorPair = Couple.of(record.getAuthorName(), record.getAuthorEmail());
Couple<String> committerPair = Couple.of(record.getCommitterName(), record.getCommitterEmail());
Collection<String> parents = Arrays.asList(parentHashes);
consumer.consume(new GitFileRevision(project, finalRoot, revisionPath, revision, Couple.of(authorPair, committerPair), message, null, new Date(record.getAuthorTimeStamp()), parents));
List<GitLogStatusInfo> statusInfos = record.getStatusInfos();
if (statusInfos.isEmpty()) {
return;
}
if (statusInfos.get(0).getType() == GitChangeType.ADDED && !filePath.isDirectory()) {
skipFurtherOutput.set(true);
}
} catch (VcsException e) {
exceptionConsumer.consume(e);
}
};
GitVcs vcs = GitVcs.getInstance(project);
GitVersion version = vcs != null ? vcs.getVersion() : GitVersion.NULL;
final AtomicBoolean criticalFailure = new AtomicBoolean();
while (currentPath.get() != null && firstCommitParent.get() != null) {
logHandler.set(getLogHandler(project, version, finalRoot, logParser, currentPath.get(), firstCommitParent.get(), parameters));
final MyTokenAccumulator accumulator = new MyTokenAccumulator(logParser);
final Semaphore semaphore = new Semaphore();
logHandler.get().addLineListener(new GitLineHandlerAdapter() {
@Override
public void onLineAvailable(String line, Key outputType) {
final GitLogRecord record = accumulator.acceptLine(line);
if (record != null) {
resultAdapter.consume(record);
}
}
@Override
public void startFailed(Throwable exception) {
//noinspection ThrowableInstanceNeverThrown
try {
exceptionConsumer.consume(new VcsException(exception));
} finally {
criticalFailure.set(true);
semaphore.up();
}
}
@Override
public void processTerminated(int exitCode) {
try {
super.processTerminated(exitCode);
final GitLogRecord record = accumulator.processLast();
if (record != null) {
resultAdapter.consume(record);
}
} catch (ProcessCanceledException ignored) {
} catch (Throwable t) {
LOG.error(t);
exceptionConsumer.consume(new VcsException("Internal error " + t.getMessage(), t));
criticalFailure.set(true);
} finally {
semaphore.up();
}
}
});
semaphore.down();
logHandler.get().start();
semaphore.waitFor();
if (criticalFailure.get()) {
return;
}
try {
Pair<String, FilePath> firstCommitParentAndPath = getFirstCommitParentAndPathIfRename(project, finalRoot, firstCommit.get(), currentPath.get(), version);
currentPath.set(firstCommitParentAndPath == null ? null : firstCommitParentAndPath.second);
firstCommitParent.set(firstCommitParentAndPath == null ? null : firstCommitParentAndPath.first);
skipFurtherOutput.set(false);
} catch (VcsException e) {
LOG.warn("Tried to get first commit rename path", e);
exceptionConsumer.consume(e);
return;
}
}
}
Aggregations