List of usage examples for org.eclipse.jgit.lib Constants HEAD
String HEAD
To view the source code for org.eclipse.jgit.lib Constants HEAD.
Click Source Link
From source file:org.jenkinsci.git.RepositoryCheckoutOperation.java
License:Open Source License
public Boolean invoke(File file, VirtualChannel channel) throws IOException, InterruptedException { CommitLogWriter writer = new CommitLogWriter(new OutputStreamWriter(log.write())); CommitLogWriterFilter filter = new CommitLogWriterFilter(writer); StreamProgressMonitor monitor = null; if (listener != null) monitor = new StreamProgressMonitor(listener.getLogger()); try {//from w w w .java 2 s . co m for (BuildRepository repo : repos) { Repository gitRepo = new FileRepositoryOperation(repo).invoke(file, channel); RevCommit current = null; if (gitRepo == null) gitRepo = new InitOperation(repo).invoke(file, channel); else current = CommitUtils.getLatest(gitRepo); RevCommit fetched = new FetchOperation(repo, gitRepo, monitor).call(); if (fetched == null) return false; if (current != null) new CommitFinder(gitRepo).setFilter(filter).findBetween(fetched, current); else writer.write(new Commit(gitRepo, fetched)); new TreeCheckoutOperation(gitRepo, fetched).call(); RefUpdate refUpdate = gitRepo.updateRef(Constants.HEAD, true); refUpdate.setNewObjectId(fetched); Result result = refUpdate.forceUpdate(); if (result == null) throw new IOException("Null ref update result"); switch (result) { case NEW: case FORCED: case FAST_FORWARD: case NO_CHANGE: // These are the acceptable results break; default: throw new IOException(result.name()); } } } finally { writer.close(); } return true; }
From source file:org.jenkinsci.plugins.gitclient.GitClientTest.java
private ObjectId commitFile(final String path, final String content, final String commitMessage) throws Exception { createFile(path, content);//from w w w. j av a 2 s .c o m gitClient.add(path); gitClient.commit(commitMessage); List<ObjectId> headList = gitClient.revList(Constants.HEAD); assertThat(headList.size(), is(greaterThan(0))); return headList.get(0); }
From source file:org.jenkinsci.plugins.gitclient.GitClientTest.java
@Test public void testgetRemoteSymbolicReferences_null() throws Exception { assumeTrue(CLI_GIT_SUPPORTS_SYMREF); commitOneFile("A-Single-File-Commit"); assertThat(gitClient.getRemoteSymbolicReferences(repoRoot.getAbsolutePath(), null), hasEntry(Constants.HEAD, "refs/heads/master")); }
From source file:org.jenkinsci.plugins.gitclient.GitClientTest.java
@Test public void testgetRemoteSymbolicReferences_null_old_git_use_jgit() throws Exception { assumeFalse(CLI_GIT_SUPPORTS_SYMREF); assumeThat(gitImplName, is(not("git"))); commitOneFile("A-Single-File-Commit"); assertThat(gitClient.getRemoteSymbolicReferences(repoRoot.getAbsolutePath(), null), hasEntry(Constants.HEAD, "refs/heads/master")); }
From source file:org.jenkinsci.plugins.gitclient.GitClientTest.java
@Test public void testgetRemoteSymbolicReferences_with_matching_pattern() throws Exception { assumeTrue(CLI_GIT_SUPPORTS_SYMREF); commitOneFile("A-Single-File-Commit"); assertThat(gitClient.getRemoteSymbolicReferences(repoRoot.getAbsolutePath(), Constants.HEAD), hasEntry(Constants.HEAD, "refs/heads/master")); }
From source file:org.jenkinsci.plugins.gitclient.GitClientTest.java
@Test public void testgetRemoteSymbolicReferences_with_matching_pattern_old_git() throws Exception { assumeFalse(CLI_GIT_SUPPORTS_SYMREF); assumeThat(gitImplName, is("git")); commitOneFile("A-Single-File-Commit"); assertThat(gitClient.getRemoteSymbolicReferences(repoRoot.getAbsolutePath(), Constants.HEAD).keySet(), hasSize(0));// ww w . j a v a 2 s. c o m }
From source file:org.jenkinsci.plugins.gitclient.GitClientTest.java
@Test public void testgetRemoteSymbolicReferences_with_matching_pattern_old_git_with_jgit() throws Exception { assumeFalse(CLI_GIT_SUPPORTS_SYMREF); assumeThat(gitImplName, is(not("git"))); commitOneFile("A-Single-File-Commit"); assertThat(gitClient.getRemoteSymbolicReferences(repoRoot.getAbsolutePath(), Constants.HEAD), hasEntry(Constants.HEAD, "refs/heads/master")); }
From source file:org.jenkinsci.plugins.gitclient.GitClientTest.java
@Test public void testgetRemoteSymbolicReferences_with_non_default_HEAD() throws Exception { assumeTrue(CLI_GIT_SUPPORTS_SYMREF); commitOneFile("A-Single-File-Commit"); CliGitCommand gitCmd = new CliGitCommand(gitClient); gitCmd.run("checkout", "-b", "new-branch"); gitCmd.assertOutputContains(".*Switched to a new branch.*"); commitOneFile("A-Second-File-Commit"); gitCmd = new CliGitCommand(gitClient); gitCmd.run("symbolic-ref", Constants.HEAD, "refs/heads/new-branch"); assertThat(gitClient.getRemoteSymbolicReferences(repoRoot.getAbsolutePath(), Constants.HEAD), hasEntry(Constants.HEAD, "refs/heads/new-branch")); assertThat(gitClient.getRemoteSymbolicReferences(repoRoot.getAbsolutePath(), null), hasEntry(Constants.HEAD, "refs/heads/new-branch")); }
From source file:org.jenkinsci.plugins.gitclient.GitClientTest.java
@Test(expected = GitException.class) public void testgetRemoteSymbolicReferences_URI_Syntax() throws Exception { assumeTrue(CLI_GIT_SUPPORTS_SYMREF); gitClient.getRemoteSymbolicReferences("error: invalid repo URL", Constants.HEAD); }
From source file:org.jenkinsci.plugins.gitclient.GitClientTest.java
@Test(expected = GitException.class) public void testgetRemoteSymbolicReferences_URI_Syntax_old_jgit() throws Exception { assumeFalse(CLI_GIT_SUPPORTS_SYMREF); assumeThat(gitImplName, is(not("git"))); gitClient.getRemoteSymbolicReferences("error: invalid repo URL", Constants.HEAD); }