List of usage examples for org.eclipse.jgit.api Git commit
public CommitCommand commit()
From source file:org.eclipse.egit.core.synchronize.ThreeWayDiffEntryTest.java
License:Open Source License
@Test public void shouldListConflictingModify() throws Exception { // given//w w w . j a v a 2 s . co m writeTrashFile("a.txt", "content"); Git git = new Git(db); git.add().addFilepattern("a.txt").call(); RevCommit c = git.commit().setMessage("initial commit").call(); writeTrashFile("a.txt", "new line"); RevCommit c1 = git.commit().setAll(true).setMessage("second commit").call(); // when TreeWalk walk = new TreeWalk(db); walk.addTree(c1.getTree()); walk.addTree(c.getTree()); walk.addTree(c1.getTree()); List<ThreeWayDiffEntry> result = ThreeWayDiffEntry.scan(walk); // then assertThat(result, notNullValue()); assertThat(Integer.valueOf(result.size()), is(Integer.valueOf(1))); ThreeWayDiffEntry entry = result.get(0); assertThat(entry.getDirection(), is(Direction.CONFLICTING)); assertThat(entry.getChangeType(), is(ChangeType.MODIFY)); assertThat(entry.getPath(), is("a.txt")); }
From source file:org.eclipse.egit.core.test.GitProjectSetCapabilityTest.java
License:Open Source License
private File createRepository(IPath location, String url, String branch) throws Exception { File gitDirectory = new File(location.toFile(), Constants.DOT_GIT); Repository repo = new FileRepository(gitDirectory); repo.getConfig().setString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", ConfigConstants.CONFIG_KEY_URL, url);/*w ww. j a v a 2 s . co m*/ repo.getConfig().setString(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_REMOTE, "origin"); repo.create(); repo.close(); Git git = new Git(repo); git.add().addFilepattern(".").call(); git.commit().setMessage("initial").call(); if (!branch.equals("master")) git.checkout().setName(branch).setCreateBranch(true).call(); pathsToClean.add(gitDirectory); return gitDirectory; }
From source file:org.eclipse.egit.core.test.internal.mapping.HistoryTest.java
License:Open Source License
@Before public void setUp() throws Exception { super.setUp(); // ensure we are working on an empty repository if (gitDir.exists()) FileUtils.delete(gitDir, FileUtils.RECURSIVE | FileUtils.RETRY); thisGit = new FileRepository(gitDir); workDir = thisGit.getWorkTree();/* w w w . j a v a 2 s .c o m*/ thisGit.create(); Git git = new Git(thisGit); createFile("Project-1/A.txt", "A.txt - first version\n"); createFile("Project-1/B.txt", "B.txt - first version\n"); git.add().addFilepattern("Project-1/A.txt").addFilepattern("Project-1/B.txt").call(); git.commit().setAuthor(jauthor).setCommitter(jcommitter).setMessage("Foo\n\nMessage").call(); createFile("Project-1/B.txt", "B.txt - second version\n"); git.add().addFilepattern("Project-1/B.txt").call(); git.commit().setAuthor(jauthor).setCommitter(jcommitter).setMessage("Modified").call(); ConnectProviderOperation operation = new ConnectProviderOperation(project.getProject(), gitDir); operation.execute(null); }
From source file:org.eclipse.egit.core.test.op.CloneOperationTest.java
License:Open Source License
@Before public void setUp() throws Exception { workdir = testUtils.createTempDir("Repository1"); workdir2 = testUtils.createTempDir("Repository2"); repository1 = new TestRepository(new File(workdir, Constants.DOT_GIT)); File file = new File(workdir, "file1.txt"); FileUtils.createNewFile(file);//from w ww . j a va2 s .c o m Git git = new Git(repository1.getRepository()); git.add().addFilepattern("file1.txt").call(); git.commit().setMessage("first commit").call(); }
From source file:org.eclipse.egit.core.test.op.CloneOperationTest.java
License:Open Source License
protected void createNoteInOrigin() throws GitAPIException { Git git = new Git(repository1.getRepository()); git.add().addFilepattern("file.txt").call(); RevCommit commit = git.commit().setMessage("Initial commit").call(); git.notesAdd().setNotesRef("refs/notes/review").setObjectId(commit).setMessage("text").call(); }
From source file:org.eclipse.egit.core.test.TestRepository.java
License:Open Source License
/** * Commits the current index/*from ww w . j av a 2 s .co m*/ * * @param message * commit message * @return commit object * * @throws NoHeadException * @throws NoMessageException * @throws UnmergedPathException * @throws ConcurrentRefUpdateException * @throws JGitInternalException * @throws WrongRepositoryStateException */ public RevCommit commit(String message) throws NoHeadException, NoMessageException, UnmergedPathException, ConcurrentRefUpdateException, JGitInternalException, WrongRepositoryStateException { Git git = new Git(repository); CommitCommand commitCommand = git.commit(); commitCommand.setAuthor("J. Git", "j.git@egit.org"); commitCommand.setCommitter(commitCommand.getAuthor()); commitCommand.setMessage(message); return commitCommand.call(); }
From source file:org.eclipse.egit.internal.relengtools.GitCopyrightAdapterTest.java
License:Open Source License
@Test public void testLastModifiedYear() throws Exception { final Git git = new Git(db); git.add().addFilepattern(PROJECT_NAME + "/" + FILE_NAME).call(); final PersonIdent committer2012 = new PersonIdent(committer, getDateForYear(2012)); git.commit().setMessage("initial commit").setCommitter(committer2012).call(); final GitCopyrightAdapter adapter = new GitCopyrightAdapter(new IResource[] { project }); adapter.initialize(NULL_MONITOR);/*from w w w .ja v a 2 s . co m*/ final int lastModifiedYear = adapter.getLastModifiedYear(file, NULL_MONITOR); assertEquals(2012, lastModifiedYear); }
From source file:org.eclipse.egit.internal.relengtools.GitCopyrightAdapterTest.java
License:Open Source License
@Test public void testCopyrightUpdateComment() throws Exception { final Git git = new Git(db); git.add().addFilepattern(PROJECT_NAME + "/" + FILE_NAME).call(); git.commit().setMessage("copyright update").call(); final GitCopyrightAdapter adapter = new GitCopyrightAdapter(new IResource[] { project }); adapter.initialize(NULL_MONITOR);/*w w w . ja v a 2 s. c om*/ final int lastModifiedYear = adapter.getLastModifiedYear(file, NULL_MONITOR); assertEquals(0, lastModifiedYear); }
From source file:org.eclipse.egit.ui.gitflow.AbstractGitflowHandlerTest.java
License:Open Source License
protected RevCommit setContentAddAndCommit(String newContent) throws Exception, GitAPIException, NoHeadException, NoMessageException, UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException, AbortedByHookException, IOException { setTestFileContent(newContent);//from w w w. j ava 2s.co m Git git = Git.wrap(repository); git.add().addFilepattern(".").call(); CommitCommand commit = git.commit().setMessage(newContent); commit.setAuthor(TestUtil.TESTCOMMITTER_NAME, TestUtil.TESTCOMMITTER_EMAIL); commit.setCommitter(TestUtil.TESTCOMMITTER_NAME, TestUtil.TESTCOMMITTER_EMAIL); return commit.call(); }
From source file:org.eclipse.egit.ui.httpauth.PushTest.java
License:Open Source License
@Test public void testPush() throws Exception { // change file TestUtil.appendFileContent(file, "additional content", true); // commit change Git git = new Git(localRepository); git.add().addFilepattern(SampleTestRepository.A_txt_name).call(); git.commit().setMessage("Change").call(); configurePush();// www . j a v a 2s.co m // push change PushWizardTester wizardTester = new PushWizardTester(); RepoPropertiesPage repoPropertiesPage = wizardTester.openPushWizard(localRepository); repoPropertiesPage.setPushDestination("push"); wizardTester.nextPage(); // now login dialog appears LoginDialogTester loginDialogTester = new LoginDialogTester(); loginDialogTester.login("agitter", "letmein"); RefSpecPageTester refSpecPageTester = new RefSpecPageTester(); refSpecPageTester.waitUntilPageIsReady(1); wizardTester.finish(); loginDialogTester.login("agitter", "letmein"); PushResultDialogTester pushResultDialogTester = new PushResultDialogTester(); String expectedMessage = "Repository " + remoteRepository.getUri(); pushResultDialogTester.assertResultMessage(expectedMessage); pushResultDialogTester.closeDialog(); }