Example usage for org.eclipse.jgit.lib Constants HEAD

List of usage examples for org.eclipse.jgit.lib Constants HEAD

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants HEAD.

Prototype

String HEAD

To view the source code for org.eclipse.jgit.lib Constants HEAD.

Click Source Link

Document

Special name for the "HEAD" symbolic-ref.

Usage

From source file:org.openengsb.connector.git.internal.GitServiceImplTest.java

License:Apache License

public void exportRepositoryByRef_shouldReturnZipFileWithRepoEntries() throws Exception {
    localRepository = RepositoryFixture.createRepository(localDirectory);

    String dir = "testDirectory";
    String file = "myTestFile";
    File parent = new File(localDirectory, dir);
    parent.mkdirs();//from   w w w. jav  a  2  s .  co  m
    File child = new File(parent, file);
    FileWriter fw = new FileWriter(child);
    fw.write(file + "\n");
    fw.close();

    String pattern = dir + "/" + file;
    Git git = new Git(localRepository);
    git.add().addFilepattern(pattern).call();
    git.commit().setMessage("My msg").call();

    AnyObjectId headId = localRepository.resolve(Constants.HEAD);
    RevWalk rw = new RevWalk(localRepository);
    RevCommit head = rw.parseCommit(headId);
    rw.release();

    ZipFile zipFile = new ZipFile(service.export(new GitCommitRef(head)));
    assertThat(zipFile.getEntry("testfile").getName(), is("testfile"));
    assertThat(zipFile.getEntry(dir + "/").getName(), is(dir + "/"));
    assertThat(zipFile.getEntry(dir + "\\" + file).getName(), is(dir + "\\" + file));
}

From source file:org.openengsb.connector.git.internal.GitServiceImplTest.java

License:Apache License

@Test
public void getFileFromCommitByRef_shouldReturnFileWithCorrectContent() throws Exception {
    String fileName = "myFile";

    localRepository = RepositoryFixture.createRepository(localDirectory);
    AnyObjectId head = localRepository.resolve(Constants.HEAD);
    RevWalk rw = new RevWalk(localRepository);
    RevCommit headCommit = rw.parseCommit(head);
    rw.release();//www . j  a  v a  2 s. co m
    Git git = new Git(localRepository);
    RepositoryFixture.addFile(git, fileName);
    RepositoryFixture.commit(git, "Commited my file");

    File file = service.get("testfile", new GitCommitRef(headCommit));
    String content = new BufferedReader(new FileReader(file)).readLine();
    assertThat(content, is("testfile"));
}

From source file:org.openengsb.connector.git.internal.GitServiceImplTest.java

License:Apache License

@Test
public void addFile_shouldReturnHeadReference() throws IOException {
    File toCommit = new File(localDirectory, "testfile");
    toCommit.createNewFile();/*from   www  .  j av  a 2  s  .c  o  m*/
    CommitRef commitRef = service.add("testcomment", toCommit);
    assertThat(commitRef, notNullValue());
    localRepository = service.getRepository();
    assertThat(commitRef.getStringRepresentation(), is(localRepository.resolve(Constants.HEAD).name()));
}

From source file:org.openengsb.connector.git.internal.GitServiceImplTest.java

License:Apache License

@Test
public void removeFileFromRepository_shouldReturnNewCommitRefAndDeleteFile() throws Exception {
    localRepository = RepositoryFixture.createRepository(localDirectory);
    AnyObjectId headId = localRepository.resolve(Constants.HEAD);
    RevWalk rw = new RevWalk(localRepository);
    RevCommit head = rw.parseCommit(headId);
    rw.release();/* w  w w . j a v a2 s .  c om*/

    CommitRef ref = service.remove("remove", new File(localDirectory, "testfile"));
    assertThat(head.name(), not(ref.getStringRepresentation()));

    File removed = new File(localDirectory, "testfile");
    assertThat(removed.exists(), is(false));
}

From source file:org.openengsb.connector.git.internal.GitServiceImplTest.java

License:Apache License

@Test
public void removeDirectoryFromRepository_shouldReturnNewCommitRefAndDeleteFiles() throws Exception {
    localRepository = RepositoryFixture.createRepository(localDirectory);

    String dir = "testDirectory";
    String file = "testFile";
    File parent = new File(localDirectory, dir);
    parent.mkdirs();//from w  ww.  jav a  2 s .co  m
    File child = new File(parent, file);
    FileWriter fw = new FileWriter(child);
    fw.write(file + "\n");
    fw.close();
    assertThat(child.exists(), is(true));

    Git git = new Git(localRepository);
    git.add().addFilepattern(dir + "/" + file).call();
    git.commit().setMessage("comment").call();

    AnyObjectId headId = localRepository.resolve(Constants.HEAD);
    RevWalk rw = new RevWalk(localRepository);
    RevCommit head = rw.parseCommit(headId);
    rw.release();

    CommitRef ref = service.remove("remove", new File(localDirectory, dir));
    assertThat(head.name(), not(ref.getStringRepresentation()));

    File removed = new File(localDirectory, dir + "/" + file);
    assertThat(removed.exists(), is(false));
}

From source file:org.openengsb.connector.git.internal.GitServiceImplTest.java

License:Apache License

@Test
public void tagHeadWithName_shouldReturnTagRefWithName() throws Exception {
    localRepository = RepositoryFixture.createRepository(localDirectory);
    String tagName = "newTag";
    TagRef tag = service.tagRepo(tagName);
    assertThat(tag, notNullValue());//from ww w.  jav a 2s  .c  om
    assertThat(tagName, is(tag.getTagName()));
    AnyObjectId tagId = localRepository.resolve(tagName);
    assertThat(tagId.name(), is(tag.getStringRepresentation()));
    RevTag revTag = new RevWalk(localRepository).parseTag(tagId);
    AnyObjectId head = localRepository.resolve(Constants.HEAD);
    assertThat(revTag.getObject().name(), is(head.name()));
}

From source file:org.openengsb.connector.git.internal.GitServiceImplTest.java

License:Apache License

@Test
public void tagCommitRefWithName_shouldReturnTagRefWithName() throws Exception {
    localRepository = RepositoryFixture.createRepository(localDirectory);
    RevWalk walk = new RevWalk(localRepository);
    RevCommit head = walk.lookupCommit(localRepository.resolve(Constants.HEAD));
    CommitRef ref = new GitCommitRef(head);
    String tagName = "newTag";
    TagRef tag = service.tagRepo(tagName, ref);
    assertThat(tag, notNullValue());//from   www.  jav  a  2 s  . co m
    assertThat(tagName, is(tag.getTagName()));
    AnyObjectId tagId = localRepository.resolve(tagName);
    assertThat(tagId.name(), is(tag.getStringRepresentation()));
    RevTag revTag = new RevWalk(localRepository).parseTag(tagId);
    assertThat(revTag.getObject().name(), is(head.name()));
}

From source file:org.openengsb.connector.git.internal.GitServiceImplTest.java

License:Apache License

@Test
public void getCommitRefForTagRef_shouldReturnTaggedCommitRef() throws Exception {
    localRepository = RepositoryFixture.createRepository(localDirectory);
    RevWalk walk = new RevWalk(localRepository);
    RevCommit head = walk.lookupCommit(localRepository.resolve(Constants.HEAD));
    String tagName = "newTag";
    TagCommand tagCommand = new Git(localRepository).tag();
    TagRef tag = new GitTagRef(tagCommand.setName(tagName).call());
    assertThat(tag, notNullValue());//from  w  w  w  .j  a  v a 2 s .c  om
    assertThat(tagName, is(tag.getTagName()));
    CommitRef commitRef = service.getCommitRefForTag(tag);
    assertThat(head.name(), is(commitRef.getStringRepresentation()));
}

From source file:org.openengsb.connector.git.internal.GitServiceImplUT.java

License:Apache License

@Test
public void pollWithEmptyWorkspace_shouldCloneSSHRemoteRepository() throws IOException {
    service.setRemoteLocation("git@github.com:Mercynary/myTestRepo.git");
    service.update();//from   w ww  .jav a2 s .  com
    localRepository = service.getRepository();
    AnyObjectId id = localRepository.resolve(Constants.HEAD);
    assertThat(id, notNullValue());
    assertThat(id.name(), is("2f610959a14c8f26549bee563ad4da8c65e1ee8b"));
}

From source file:org.openengsb.connector.git.internal.GitServiceImplUT.java

License:Apache License

@Test
public void addDirectory_shouldReturnObjectIdForChild() throws Exception {
    localRepository = RepositoryFixture.createRepository(localDirectory);

    String dir = "testDirectory";
    String file = "testFile";
    File parent = new File(localDirectory, dir);
    parent.mkdirs();//from  ww w .  jav a2  s  .c  o m
    File child = new File(parent, file);
    FileWriter fw = new FileWriter(child);
    fw.write(file + "\n");
    fw.close();

    CommitRef commitRef = service.add("testComment", parent);
    assertThat(commitRef, is(notNullValue()));

    AnyObjectId id = localRepository.resolve(Constants.HEAD);
    RevCommit commit = new RevWalk(localRepository).parseCommit(id);
    String search = dir + "/" + file;
    TreeWalk treeWalk = TreeWalk.forPath(localRepository, search, new AnyObjectId[] { commit.getTree() });
    assertThat(treeWalk, is(notNullValue()));

    ObjectId objectId = treeWalk.getObjectId(treeWalk.getTreeCount() - 1);
    assertThat(objectId, not(ObjectId.zeroId()));
}