List of usage examples for org.eclipse.jgit.api Git Git
public Git(Repository repo)
From source file:com.googlesource.gerrit.plugins.uploadvalidator.MaxPathLengthValidatorTest.java
License:Apache License
@Test public void testDeleteTooLongPath() throws Exception { try (RevWalk rw = new RevWalk(repo)) { RevCommit c = makeCommit(rw);/*from w w w. j a v a2 s . co m*/ try (Git git = new Git(repo)) { Set<File> files = new HashSet<>(); files.add(TestUtils.createEmptyFile(TOO_LONG, repo)); TestUtils.removeFiles(git, files); c = git.commit().setMessage("Delete file which is too long").call(); rw.parseCommit(c); } List<CommitValidationMessage> m = MaxPathLengthValidator.performValidation(repo, c, rw, getMaxPathLength()); assertThat(m).isEmpty(); } }
From source file:com.googlesource.gerrit.plugins.uploadvalidator.SubmoduleValidatorTest.java
License:Apache License
private RevCommit makeCommitWithSubmodule(RevWalk rw) throws IOException, GitAPIException { try (Git git = new Git(repo)) { SubmoduleAddCommand addCommand = git.submoduleAdd(); addCommand.setURI(repo.getDirectory().getCanonicalPath()); addCommand.setPath("modules/library"); addCommand.call().close();//from ww w.j a v a 2s . c o m git.add().addFilepattern(".").call(); return rw.parseCommit(git.commit().setMessage("Commit with submodule.").call()); } }
From source file:com.googlesource.gerrit.plugins.uploadvalidator.TestUtils.java
License:Apache License
public static RevCommit makeCommit(RevWalk rw, Repository repo, String message, Map<File, byte[]> files) throws IOException, GitAPIException { try (Git git = new Git(repo)) { if (files != null) { addFiles(git, files);//w ww .j a v a2s .c om } return rw.parseCommit(git.commit().setMessage(message).call()); } }
From source file:com.googlesource.gerrit.plugins.xdocs.XDocLoader.java
License:Apache License
private String replaceMacros(Repository repo, Project.NameKey project, ObjectId revId, String abbrRevId, String raw) throws GitAPIException, IOException { Map<String, String> macros = Maps.newHashMap(); String url = webUrl.get();/*from w w w.j a v a 2 s .c o m*/ if (Strings.isNullOrEmpty(url)) { url = "http://" + DEFAULT_HOST + "/"; } macros.put("URL", url); macros.put("PROJECT", project.get()); macros.put("PROJECT_URL", url + "#/admin/projects/" + project.get()); macros.put("REVISION", abbrRevId); try (Git git = new Git(repo)) { macros.put("GIT_DESCRIPTION", MoreObjects.firstNonNull(git.describe().setTarget(revId).call(), abbrRevId)); } Matcher m = Pattern.compile("(\\\\)?@([A-Z_]+)@").matcher(raw); StringBuffer sb = new StringBuffer(); while (m.find()) { String key = m.group(2); String val = macros.get(key); if (m.group(1) != null || val == null) { m.appendReplacement(sb, "@" + key + "@"); } else { m.appendReplacement(sb, val); } } m.appendTail(sb); return sb.toString(); }
From source file:com.hazelcast.utils.GitUtils.java
License:Open Source License
public static Git getGit(PropertyReader propertyReader, String repositoryName) throws IOException { Repository repoOS = new FileRepositoryBuilder() .setGitDir(new File(propertyReader.getLocalGitRoot() + repositoryName + File.separator + ".git")) .readEnvironment().setMustExist(true).build(); return new Git(repoOS); }
From source file:com.kolich.blog.components.GitRepository.java
License:Open Source License
@Injectable public GitRepository(@Required final ServletContext context, @Required final BlogEventBus eventBus) throws Exception { eventBus_ = eventBus;/* ww w . ja v a 2s . co m*/ executor_ = newSingleThreadScheduledExecutor( new ThreadFactoryBuilder().setDaemon(true).setNameFormat("blog-git-puller").build()); final File repoDir = getRepoDir(context); logger__.info("Activated repository path: {}", repoDir.getCanonicalFile()); // If were not in dev mode, and the clone path doesn't exist or we need to force clone from // scratch, do that now. final boolean clone = (!repoDir.exists() || shouldCloneOnStartup__); if (!isDevMode__ && clone) { logger__.info("Clone path does not exist, or we were asked to re-clone. Cloning from: {}", blogRepoCloneUrl__); // Recursively delete the existing clone of the repo, if it exists, and clone the repository. FileUtils.deleteDirectory(repoDir); Git.cloneRepository().setURI(blogRepoCloneUrl__).setDirectory(repoDir).setBranch("master").call(); } // Construct a new pointer to the repository on disk. repo_ = new FileRepositoryBuilder().setWorkTree(repoDir).readEnvironment().build(); git_ = new Git(repo_); logger__.info("Successfully initialized repository at: {}", repo_); }
From source file:com.madgag.agit.BranchViewer.java
License:Open Source License
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case CHECKOUT_ID: try {//w w w .j ava 2 s .c o m new Git(repo()).checkout().setName(branchName).call(); } catch (Exception e) { throw new RuntimeException(e); } return true; } return super.onOptionsItemSelected(item); }
From source file:com.madgag.agit.BranchViewer.java
License:Open Source License
private List<RevCommit> commitListForRepo() { Git git = new Git(repository); try {/* w w w .j av a 2 s. c o m*/ Ref branch = branch(); Log.d(TAG, "Calculating commitListForRepo based on " + branch + " branch.getObjectId()=" + branch.getObjectId()); Iterable<RevCommit> logWaa = git.log().add(branch.getObjectId()).call(); List<RevCommit> sampleRevCommits = newArrayList(logWaa); Log.d(TAG, "Found " + sampleRevCommits.size() + " commits"); return sampleRevCommits; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.madgag.agit.CommitViewerActivity.java
License:Open Source License
@Override protected Dialog onCreateDialog(int id) { switch (id) { case CREATE_TAG_DIALOG: LayoutInflater factory = LayoutInflater.from(this); final View textEntryView = factory.inflate(R.layout.create_tag_dialog, null); return new AlertDialog.Builder(this) // .setIcon(R.drawable.alert_dialog_icon) // .setTitle(R.string.alert_dialog_text_entry) .setView(textEntryView).setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String tagName = ((TextView) textEntryView.findViewById(R.id.tag_name_edit)).getText() .toString(); try { new Git(repo()).tag().setName(tagName).setObjectId(commit).call(); } catch (Exception e) { throw new RuntimeException(e); }/*w w w . j av a 2s .c o m*/ } }).create(); } return null; }
From source file:com.madgag.agit.LogFragment.java
License:Open Source License
@Override public Loader<List<RevCommit>> onCreateLoader(int id, Bundle args) { return new AsyncLoader<List<RevCommit>>(getActivity()) { public List<RevCommit> loadInBackground() { Stopwatch stopwatch = new Stopwatch().start(); Bundle args = getArguments(); try { Repository repo = new FileRepository(args.getString(GITDIR)); LogCommand log = new Git(repo).log(); List<String> untilRevs = getArguments().getStringArrayList(UNTIL_REVS); if (untilRevs == null || untilRevs.isEmpty()) { log.all();/*from w w w .ja va2 s . c o m*/ } else { for (String untilRev : untilRevs) { log.add(repo.resolve(untilRev)); } } List<RevCommit> sampleRevCommits = newArrayList(log.call()); Log.d(TAG, "Found " + sampleRevCommits.size() + " commits " + stopwatch); return sampleRevCommits; } catch (Exception e) { throw new RuntimeException(e); } } }; }