List of usage examples for org.eclipse.jgit.api Git Git
public Git(Repository repo)
From source file:org.eclipse.egit.internal.relengtools.GetBugsOperation.java
License:Open Source License
private void getBugNumbersForProject(IProject project, IProgressMonitor monitor, Set<Integer> set) throws Exception { final RepositoryMapping rm = RepositoryMapping.getMapping(project); final Repository repository = rm.getRepository(); final RevCommit previousCommit = ShowInfoHandler.getCommitForTag(repository, getProjectTag(project).getName()); final RevCommit latestCommit = ShowInfoHandler.getLatestCommitFor(rm, repository, project); final Git git = new Git(repository); final LogCommand log = git.log(); log.addRange(previousCommit, latestCommit); for (final RevCommit commit : log.call()) { findBugNumber(commit.getFullMessage(), set); }/*from ww w. ja v a 2 s . c o m*/ }
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 .j a va 2 s. c o 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);/*from ww w. jav a2s . c om*/ final int lastModifiedYear = adapter.getLastModifiedYear(file, NULL_MONITOR); assertEquals(0, lastModifiedYear); }
From source file:org.eclipse.egit.internal.relengtools.ShowInfoHandler.java
License:Open Source License
public static void showLogBetween(final Repository repo, final RevCommit oldCommit, final RevCommit newCommit) throws MissingObjectException, IncorrectObjectTypeException, NoHeadException, Exception { final Git git = new Git(repo); final LogCommand command = git.log(); command.addRange(oldCommit, newCommit); System.out.println("\nCommits:"); for (final RevCommit rc : command.call()) { System.out.println(rc);// w w w. ja v a 2 s . c o m System.out.print("Tags: "); System.out.println(getTagsForCommit(repo, rc)); System.out.println(rc.getShortMessage()); } }
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();// w w w .j av a 2s. c o 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(); }
From source file:org.eclipse.egit.ui.internal.actions.SwitchToMenuTest.java
License:Open Source License
@Test public void selectionWithProj1AndReflog() throws Exception { File gitDir = createProjectAndCommitToRepository(); // create additional reflog entries Git git = new Git(lookupRepository(gitDir)); git.checkout().setName("stable").call(); git.checkout().setName("master").call(); selectionWithProj1Common();//from ww w . j av a 2s .co m // delete reflog again to not confuse other tests new File(gitDir, Constants.LOGS + "/" + Constants.HEAD).delete(); }
From source file:org.eclipse.egit.ui.internal.decorators.DecoratableResourceAdapterTest.java
License:Open Source License
@Before public void setUp() throws Exception { gitDir = createProjectAndCommitToRepository(); project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1); FileRepository repo = lookupRepository(gitDir); git = new Git(repo); indexDiffCacheEntry = Activator.getDefault().getIndexDiffCache().getIndexDiffCacheEntry(repo); waitForIndexDiffUpdate(false);/*from ww w . ja va 2 s . c o m*/ }
From source file:org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog.java
License:Open Source License
@Override protected void createButtonsForButtonBar(Composite parent) { newButton = new Button(parent, SWT.PUSH); newButton.setFont(JFaceResources.getDialogFont()); newButton.setText(UIText.BranchSelectionDialog_NewBranch); setButtonLayoutData(newButton);//from ww w. j a va 2 s . c o m ((GridLayout) parent.getLayout()).numColumns++; renameButton = new Button(parent, SWT.PUSH); renameButton.setFont(JFaceResources.getDialogFont()); renameButton.setText(UIText.BranchSelectionDialog_Rename); setButtonLayoutData(renameButton); ((GridLayout) parent.getLayout()).numColumns++; renameButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String refName = refNameFromDialog(); String refPrefix; if (refName.startsWith(Constants.R_HEADS)) refPrefix = Constants.R_HEADS; else if (refName.startsWith(Constants.R_REMOTES)) refPrefix = Constants.R_REMOTES; else if (refName.startsWith(Constants.R_TAGS)) refPrefix = Constants.R_TAGS; else { // the button should be disabled anyway, but we check again return; } String branchName = refName.substring(refPrefix.length()); InputDialog labelDialog = getRefNameInputDialog( NLS .bind( UIText.BranchSelectionDialog_QuestionNewBranchNameMessage, branchName, refPrefix), refPrefix, branchName); if (labelDialog.open() == Window.OK) { String newRefName = refPrefix + labelDialog.getValue(); try { new Git(repo).branchRename().setOldName(refName) .setNewName(labelDialog.getValue()).call(); branchTree.refresh(); markRef(newRefName); } catch (Throwable e1) { reportError( e1, UIText.BranchSelectionDialog_ErrorCouldNotRenameRef, refName, newRefName, e1.getMessage()); } } } }); newButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { // check what Ref the user selected if any Ref ref = refFromDialog(); InputDialog labelDialog = getRefNameInputDialog(NLS.bind( UIText.BranchSelectionDialog_QuestionNewBranchMessage, ref.getName(), Constants.R_HEADS), Constants.R_HEADS, null); if (labelDialog.open() == Window.OK) { String newRefName = labelDialog.getValue(); CreateLocalBranchOperation cbop = new CreateLocalBranchOperation( repo, newRefName, ref); try { cbop.execute(null); branchTree.refresh(); markRef(Constants.R_HEADS + newRefName); } catch (Throwable e1) { reportError( e1, UIText.BranchSelectionDialog_ErrorCouldNotCreateNewRef, newRefName); } } } }); super.createButtonsForButtonBar(parent); getButton(Window.OK).setText(UIText.BranchSelectionDialog_OkCheckout); // createButton(parent, IDialogConstants.OK_ID, // UIText.BranchSelectionDialog_OkCheckout, true); // createButton(parent, IDialogConstants.CANCEL_ID, // IDialogConstants.CANCEL_LABEL, false); // can't advance without a selection getButton(Window.OK).setEnabled(!branchTree.getSelection().isEmpty()); }
From source file:org.eclipse.egit.ui.internal.dialogs.CheckoutDialog.java
License:Open Source License
@Override protected void createButtonsForButtonBar(Composite parent) { newButton = new Button(parent, SWT.PUSH); newButton.setFont(JFaceResources.getDialogFont()); newButton.setText(UIText.CheckoutDialog_NewBranch); setButtonLayoutData(newButton);// w w w.jav a 2 s . c o m ((GridLayout) parent.getLayout()).numColumns++; renameButton = new Button(parent, SWT.PUSH); renameButton.setFont(JFaceResources.getDialogFont()); renameButton.setText(UIText.CheckoutDialog_Rename); setButtonLayoutData(renameButton); ((GridLayout) parent.getLayout()).numColumns++; deleteteButton = new Button(parent, SWT.PUSH); deleteteButton.setFont(JFaceResources.getDialogFont()); deleteteButton.setText(UIText.CheckoutDialog_Delete); setButtonLayoutData(deleteteButton); ((GridLayout) parent.getLayout()).numColumns++; renameButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { String refName = refNameFromDialog(); String refPrefix; if (refName.startsWith(Constants.R_HEADS)) refPrefix = Constants.R_HEADS; else if (refName.startsWith(Constants.R_REMOTES)) refPrefix = Constants.R_REMOTES; else if (refName.startsWith(Constants.R_TAGS)) refPrefix = Constants.R_TAGS; else { // the button should be disabled anyway, but we check again return; } String branchName = refName.substring(refPrefix.length()); InputDialog labelDialog = getRefNameInputDialog( NLS.bind(UIText.CheckoutDialog_QuestionNewBranchNameMessage, branchName, refPrefix), refPrefix, branchName); if (labelDialog.open() == Window.OK) { String newRefName = refPrefix + labelDialog.getValue(); try { new Git(repo).branchRename().setOldName(refName).setNewName(labelDialog.getValue()).call(); branchTree.refresh(); markRef(newRefName); } catch (Throwable e1) { reportError(e1, UIText.CheckoutDialog_ErrorCouldNotRenameRef, refName, newRefName, e1.getMessage()); } } } }); newButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { CreateBranchWizard wiz = new CreateBranchWizard(repo, refNameFromDialog()); if (new WizardDialog(getShell(), wiz).open() == Window.OK) { String newRefName = wiz.getNewBranchName(); try { branchTree.refresh(); markRef(Constants.R_HEADS + newRefName); if (repo.getBranch().equals(newRefName)) // close branch selection dialog when new branch was // already checked out from new branch wizard CheckoutDialog.this.okPressed(); } catch (Throwable e1) { reportError(e1, UIText.CheckoutDialog_ErrorCouldNotCreateNewRef, newRefName); } } } }); deleteteButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent selectionEvent) { try { CommonUtils.runCommand(IWorkbenchCommandConstants.EDIT_DELETE, (IStructuredSelection) branchTree.getSelection()); branchTree.refresh(); } catch (Throwable e) { reportError(e, UIText.CheckoutDialog_ErrorCouldNotDeleteRef, refNameFromDialog()); } } }); super.createButtonsForButtonBar(parent); getButton(Window.OK).setText(UIText.CheckoutDialog_OkCheckout); // can't advance without a selection getButton(Window.OK).setEnabled(!branchTree.getSelection().isEmpty()); }
From source file:org.eclipse.egit.ui.internal.dialogs.RenameBranchDialog.java
License:Open Source License
@Override protected void okPressed() { String refName = refNameFromDialog(); String refPrefix;//from w w w. j av a 2s . c o m if (refName.startsWith(Constants.R_HEADS)) refPrefix = Constants.R_HEADS; else if (refName.startsWith(Constants.R_REMOTES)) refPrefix = Constants.R_REMOTES; else if (refName.startsWith(Constants.R_TAGS)) refPrefix = Constants.R_TAGS; else { // the button should be disabled anyway, but we check again return; } String branchName = refName.substring(refPrefix.length()); InputDialog labelDialog = getRefNameInputDialog( NLS.bind(UIText.RenameBranchDialog_NewNameInputDialogPrompt, branchName, refPrefix), refPrefix, branchName); if (labelDialog.open() == Window.OK) { String newRefName = refPrefix + labelDialog.getValue(); try { new Git(repo).branchRename().setOldName(refName).setNewName(labelDialog.getValue()).call(); branchTree.refresh(); markRef(newRefName); } catch (Throwable e1) { reportError(e1, UIText.RenameBranchDialog_RenameErrorMessage, refName, newRefName, e1.getMessage()); } } super.okPressed(); }