use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class GitHistoryUtilsTest method testGetLastRevisionForNonExistingFile.
public void testGetLastRevisionForNonExistingFile() throws Exception {
git("remote add origin git://example.com/repo.git");
git("config branch.master.remote origin");
git("config branch.master.merge refs/heads/master");
git("rm " + bfile.getPath());
commit("removed bfile");
String[] hashAndDate = log("--pretty=format:%H#%ct", "-n1").split("#");
// to avoid pushing to this fake origin
git("update-ref refs/remotes/origin/master HEAD");
touch("dir/b.txt", "content");
addCommit("recreated bfile");
refresh();
myRepo.update();
final ItemLatestState state = GitHistoryUtils.getLastRevision(myProject, toFilePath(bfile));
assertTrue(!state.isItemExists());
final GitRevisionNumber revisionNumber = (GitRevisionNumber) state.getNumber();
assertEquals(revisionNumber.getRev(), hashAndDate[0]);
assertEquals(revisionNumber.getTimestamp(), GitTestRevision.gitTimeStampToDate(hashAndDate[1]));
}
use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class GitHistoryUtilsTest method testGetCurrentRevisionInMasterBranch.
@Test
public void testGetCurrentRevisionInMasterBranch() throws Exception {
GitRevisionNumber revisionNumber = (GitRevisionNumber) GitHistoryUtils.getCurrentRevision(myProject, toFilePath(bfile), "master");
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 GitChangesParser method prepareParentRevisions.
private static List<GitRevisionNumber> prepareParentRevisions(List<String> parentsHashes) {
final List<AbstractHash> parents = new ArrayList<>(parentsHashes.size());
for (String parentsShortHash : parentsHashes) {
parents.add(AbstractHash.create(parentsShortHash));
}
final List<GitRevisionNumber> parentRevisions = new ArrayList<>(parents.size());
for (AbstractHash parent : parents) {
parentRevisions.add(new GitRevisionNumber(parent.getString()));
}
return parentRevisions;
}
use of git4idea.GitRevisionNumber in project intellij-community by JetBrains.
the class MergeChangeCollector method getRevisionsForDiff.
/**
* @return The revision range which will be used to find merge diff (merge may be just finished, or in progress)
* or null in case of error or inconsistency.
*/
@Nullable
public String getRevisionsForDiff() throws VcsException {
String root = myRoot.getPath();
GitRevisionNumber currentHead = GitRevisionNumber.resolve(myProject, myRoot, "HEAD");
if (currentHead.equals(myStart)) {
// The head has not advanced. This means that this is a merge that did not commit.
// This could be caused by --no-commit option or by failed two-head merge. The MERGE_HEAD
// should be available. In case of --no-commit option, the MERGE_HEAD might contain
// multiple heads separated by newline. The changes are collected separately for each head
// and they are merged using TreeSet class (that also sorts the changes).
File mergeHeadsFile = myRepository.getRepositoryFiles().getMergeHeadFile();
try {
if (mergeHeadsFile.exists()) {
String mergeHeads = new String(FileUtil.loadFileText(mergeHeadsFile, CharsetToolkit.UTF8));
for (StringScanner s = new StringScanner(mergeHeads); s.hasMoreData(); ) {
String head = s.line();
if (head.length() == 0) {
continue;
}
// note that "..." cause the diff to start from common parent between head and merge head
return myStart.getRev() + "..." + head;
}
}
} catch (IOException e) {
//noinspection ThrowableInstanceNeverThrown
throw new VcsException("Unable to read the file " + mergeHeadsFile + ": " + e.getMessage(), e);
}
} else {
// and the expression below considers it as well.
return myStart.getRev() + "..HEAD";
}
return null;
}
Aggregations