Search in sources :

Example 26 with GitRevisionNumber

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]));
}
Also used : GitRevisionNumber(git4idea.GitRevisionNumber) ItemLatestState(com.intellij.openapi.vcs.diff.ItemLatestState)

Example 27 with GitRevisionNumber

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);
}
Also used : GitRevisionNumber(git4idea.GitRevisionNumber) Test(org.testng.annotations.Test) GitSingleRepoTest(git4idea.test.GitSingleRepoTest)

Example 28 with GitRevisionNumber

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;
}
Also used : GitRevisionNumber(git4idea.GitRevisionNumber) ArrayList(java.util.ArrayList) AbstractHash(git4idea.history.wholeTree.AbstractHash)

Example 29 with GitRevisionNumber

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;
}
Also used : GitRevisionNumber(git4idea.GitRevisionNumber) VcsException(com.intellij.openapi.vcs.VcsException) IOException(java.io.IOException) StringScanner(git4idea.util.StringScanner) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GitRevisionNumber (git4idea.GitRevisionNumber)29 VcsException (com.intellij.openapi.vcs.VcsException)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 Change (com.intellij.openapi.vcs.changes.Change)8 NotNull (org.jetbrains.annotations.NotNull)8 Nullable (org.jetbrains.annotations.Nullable)8 FilePath (com.intellij.openapi.vcs.FilePath)4 GitSingleRepoTest (git4idea.test.GitSingleRepoTest)4 Test (org.testng.annotations.Test)4 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)3 ObjectUtils.assertNotNull (com.intellij.util.ObjectUtils.assertNotNull)3 GitBranchesSearcher (git4idea.GitBranchesSearcher)3 GitSimpleHandler (git4idea.commands.GitSimpleHandler)3 GitRepository (git4idea.repo.GitRepository)3 StringScanner (git4idea.util.StringScanner)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Task (com.intellij.openapi.progress.Task)2 Pair (com.intellij.openapi.util.Pair)2