use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class GitRebaseUtils method getCurrentRebaseCommit.
/**
* Get rebase directory
*
*
* @param project
* @param root the vcs root
* @return the commit information or null if no commit information could be detected
*/
@Nullable
public static CommitInfo getCurrentRebaseCommit(@NotNull Project project, @NotNull VirtualFile root) {
File rebaseDir = getRebaseDir(project, root);
if (rebaseDir == null) {
LOG.warn("No rebase dir found for " + root.getPath());
return null;
}
File nextFile = new File(rebaseDir, "next");
int next;
try {
next = Integer.parseInt(FileUtil.loadFile(nextFile, CharsetToolkit.UTF8_CHARSET).trim());
} catch (Exception e) {
LOG.warn("Failed to load next commit number from file " + nextFile.getPath(), e);
return null;
}
File commitFile = new File(rebaseDir, String.format("%04d", next));
String hash = null;
String subject = null;
try {
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(commitFile), CharsetToolkit.UTF8_CHARSET));
try {
String line;
while ((line = in.readLine()) != null) {
if (line.startsWith("From ")) {
hash = line.substring(5, 5 + 40);
}
if (line.startsWith("Subject: ")) {
subject = line.substring("Subject: ".length());
}
if (hash != null && subject != null) {
break;
}
}
} finally {
in.close();
}
} catch (Exception e) {
LOG.warn("Failed to load next commit number from file " + commitFile, e);
return null;
}
if (subject == null || hash == null) {
LOG.info("Unable to extract information from " + commitFile + " " + hash + ": " + subject);
return null;
}
return new CommitInfo(new GitRevisionNumber(hash), subject);
}
use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class GitNewChangesCollector method getHead.
@NotNull
private VcsRevisionNumber getHead() throws VcsException {
if (myRepository != null) {
// we force update the GitRepository, because update is asynchronous, and thus the GitChangeProvider may be asked for changes
// before the GitRepositoryUpdater has captures the current revision change and has updated the GitRepository.
myRepository.update();
final String rev = myRepository.getCurrentRevision();
return rev != null ? new GitRevisionNumber(rev) : VcsRevisionNumber.NULL;
} else {
// this may happen on the project startup, when GitChangeProvider may be queried before GitRepository has been initialized.
LOG.info("GitRepository is null for root " + myVcsRoot);
return getHeadFromGit();
}
}
use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class GitOldChangesCollector method parseFiles.
private void parseFiles(String list) throws VcsException {
for (StringScanner sc = new StringScanner(list); sc.hasMoreData(); ) {
if (sc.isEol()) {
sc.nextLine();
continue;
}
char status = sc.peek();
sc.skipChars(2);
if ('?' == status) {
VirtualFile file = myVcsRoot.findFileByRelativePath(GitUtil.unescapePath(sc.line()));
if (Comparing.equal(GitUtil.gitRootOrNull(file), myVcsRoot)) {
myUnversioned.add(file);
}
} else {
//noinspection HardCodedStringLiteral
if ('M' == status) {
sc.boundedToken('\t');
String file = GitUtil.unescapePath(sc.line());
VirtualFile vFile = myVcsRoot.findFileByRelativePath(file);
if (!Comparing.equal(GitUtil.gitRootOrNull(vFile), myVcsRoot)) {
continue;
}
if (!myUnmergedNames.add(file)) {
continue;
}
// assume modify-modify conflict
ContentRevision before = GitContentRevision.createRevision(myVcsRoot, file, new GitRevisionNumber("orig_head"), myProject, false, true, true);
ContentRevision after = GitContentRevision.createRevision(myVcsRoot, file, null, myProject, false, false, true);
myChanges.add(new Change(before, after, FileStatus.MERGED_WITH_CONFLICTS));
} else {
throw new VcsException("Unsupported type of the merge conflict detected: " + status);
}
}
}
}
use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class GitHistoryUtilsTest method testGetCurrentRevisionInOtherBranch.
@Test
public void testGetCurrentRevisionInOtherBranch() throws Exception {
checkout("-b feature");
overwrite(bfile, "new content");
addCommit("new content");
final String[] output = log("master --pretty=%H#%at", "-n1").trim().split("#");
GitRevisionNumber revisionNumber = (GitRevisionNumber) GitHistoryUtils.getCurrentRevision(myProject, toFilePath(bfile), "master");
assertEquals(revisionNumber.getRev(), output[0]);
assertEquals(revisionNumber.getTimestamp(), GitTestRevision.gitTimeStampToDate(output[1]));
}
use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class GitHistoryUtilsTest method testGetCurrentRevision.
@Test
public void testGetCurrentRevision() throws Exception {
GitRevisionNumber revisionNumber = (GitRevisionNumber) GitHistoryUtils.getCurrentRevision(myProject, toFilePath(bfile), null);
assertEquals(revisionNumber.getRev(), myRevisions.get(0).myHash);
assertEquals(revisionNumber.getTimestamp(), myRevisions.get(0).myDate);
}
Aggregations