Refine search
private void commitSomething(Path path) { try (Git git = Git.open(path.toFile())) { Path emptyFilePath = Paths.get(path.toString(), EMPTY_FILE); try { Files.createFile(emptyFilePath); } catch (FileAlreadyExistsException ignore) { } git.add() .addFilepattern(".") .call(); git.commit() .setMessage("add test branch") .call(); } catch (Throwable e) { log.error("Method: commitSomething Exception", e); } }
public void run() throws Exception { addCommand.addFilepattern(CRUISE_CONFIG_XML).call(); git.commit().setAuthor(rev.getUsername(), STUDIOS_PRODUCT).setMessage(rev.getComment()).call(); } });
localPath = repository.getWorkTree(); try (Git git = new Git(repository)) { File myFile = new File(repository.getDirectory().getParent(), "testfile"); if(!myFile.createNewFile()) { throw new IOException("Could not create file " + myFile); git.add().addFilepattern(".").call(); git.commit() .setMessage("Commit all changes including additions") .call(); git.commit() .setAll(true) .setMessage("Commit changes to all files") .call(); System.out.println("Committed all changes to repository at " + repository.getDirectory());
private void addEdge(File edgeDir, File edgeFile, String fileContents) throws IOException, GitAPIException { createNewFile(edgeDir, edgeFile, fileContents); // add, commit, push edge this.gitForPush.add().addFilepattern(formEdgeFilePath(edgeDir.getParentFile().getName(), edgeDir.getName(), edgeFile.getName())).call(); this.gitForPush.commit().setMessage("Edge commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); }
@Signature public Memory commit(String message, ArrayMemory settings) throws GitAPIException { CommitCommand commit = getWrappedObject().commit(); commit.setMessage(message); if (settings != null && settings.isNotNull()) { commit.setAll(settings.valueOfIndex("all").toBoolean()); commit.setAllowEmpty(settings.valueOfIndex("allowEmpty").toBoolean()); commit.setAmend(settings.valueOfIndex("amend").toBoolean()); commit.setInsertChangeId(settings.valueOfIndex("insertChangeId").toBoolean()); commit.setNoVerify(settings.valueOfIndex("noVerify").toBoolean()); Memory author = settings.valueOfIndex("author"); if (author.isArray()) { commit.setAuthor(author.valueOfIndex("name").toString(), author.valueOfIndex("email").toString()); } Memory committer = settings.valueOfIndex("committer"); if (committer.isArray()) { commit.setCommitter(committer.valueOfIndex("name").toString(), committer.valueOfIndex("email").toString()); } if (settings.containsKey("only")) { commit.setOnly(settings.valueOfIndex("only").toString()); } if (settings.containsKey("reflogComment")) { commit.setReflogComment(settings.valueOfIndex("reflogComment").toString()); } } RevCommit call = commit.call(); return GitUtils.valueOf(call); }
try (Git git = new Git(db)) { Repository repo = git.getRepository(); String originalBranch = repo.getFullBranch(); boolean empty = repo.resolve(Constants.HEAD) == null; if (!empty) { if (repo.findRef(branch) == null) git.branchCreate().setName(branch).call(); git.checkout().setName(branch).call(); git.add().addFilepattern(filename).call(); RevCommit commit = git.commit() .setMessage(branch + ": " + filename).call();
protected CommitInfo doCreateDirectory(Git git, File rootDir, String branch, String path, PersonIdent personIdent, String commitMessage) throws Exception { File file = getFile(rootDir, path); if (file.exists()) { return null; } file.mkdirs(); String filePattern = getFilePattern(path); AddCommand add = git.add().addFilepattern(filePattern).addFilepattern("."); add.call(); CommitCommand commit = git.commit().setAll(true).setAuthor(personIdent).setMessage(commitMessage); RevCommit revCommit = commitThenPush(git, branch, commit); return createCommitInfo(revCommit); }
@Override public void flush(boolean success) { if (success) { try (Git git = gitRepository.getGit()) { Status status = git.status().call(); if (!status.isClean()) { String message = git.getRepository().parseCommit(git.getRepository().resolve(HEAD)).getFullMessage(); if(! status.getUntracked().isEmpty() || ! status.getUntrackedFolders().isEmpty()) { AddCommand addCommand = git.add(); for(String untracked : status.getUntrackedFolders()) { addCommand = addCommand.addFilepattern(untracked); } for(String untracked : status.getUntracked()) { addCommand = addCommand.addFilepattern(untracked); } addCommand.call(); } git.commit().setMessage(message).setAmend(true).setAll(true).setNoVerify(true).call(); } } catch (RevisionSyntaxException | IOException | GitAPIException ex) { throw new RuntimeException(ex); } } }
public static void main(String[] args) throws IOException, GitAPIException { final File path; try (Repository repository = CookbookHelper.createNewRepository()) { try (Git git = new Git(repository)) { path = repository.getWorkTree(); System.out.println("Repository at " + path); git.add().addFilepattern("file1.txt").call(); RevCommit rev1 = git.commit().setAuthor("test", "test@test.com").setMessage("Commit Log 1").call(); System.out.println("Rev1: " + rev1); git.add().addFilepattern("file1.txt").call(); RevCommit rev2 = git.commit().setAll(true).setAuthor("test", "test@test.com").setMessage("Commit Log 2").call(); System.out.println("Rev2: " + rev2); git.add().addFilepattern("file1.txt").call(); RevCommit rev3 = git.commit().setAll(true).setAuthor("test", "test@test.com").setMessage("Commit Log 3").call(); System.out.println("Rev3: " + rev3);
localPath = repository.getWorkTree(); try (Git git = new Git(repository)) { File file1 = new File(repository.getDirectory().getParent(), "testfile"); FileUtils.writeStringToFile(file1, "some text", "UTF-8"); File file2 = new File(repository.getDirectory().getParent(), "testfile2"); FileUtils.writeStringToFile(file2, "some text", "UTF-8"); git.add() .addFilepattern("testfile") .call(); git.add() .addFilepattern("testfile2") .call(); git.commit() .setMessage("Added testfiles") .call();
result = Git.cloneRepository().setURI(remotePath).setDirectory(new File(localPath)).call(); } catch (Exception e) { LOGGER.error("Error cloning backup git repo"); git = new Git(backupRepo); File myfile = new File(localPath + "/" + fileName); git.add().addFilepattern(".").call(); } catch (GitAPIException e) { LOGGER.error("Error adding files to git"); git.commit().setMessage("Taking backup on " + new Date()).call(); git.close(); if (result != null) result.getRepository().close(); backupRepo.close();
fileKey.open(false).create(true); this.gitForPush = Git.cloneRepository().setURI(GIT_REMOTE_REPO_DIR).setDirectory(new File(GIT_CLONE_DIR)).call(); this.gitForPush.commit().setMessage("First commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(new RefSpec("master")).call();
public URI push(File source, String name) throws Exception { init(); File gitRoot = new File("target", name); FileUtils.copyDirectory(source, gitRoot); // Push via port forward String repoUrl = String.format("http://localhost:%s/%s", GIT_LOCALPORT, name); Git git = Git.init().setDirectory(gitRoot).call(); Repository repo = git.getRepository(); repo.getConfig().setString("remote", "origin", "url", repoUrl); repo.getConfig().save(); git.add().addFilepattern(".").call(); git.commit().setMessage("testing").setAuthor("Arquillian", "cube@discuss.arquillian.org").call(); git.push().setRemote("origin").setPushAll().setForce(true).call(); repo.close(); // Return an internal service name, for use within the openshift network String serverUrl = String.format("http://%s:%s/%s", GIT_SERVICE, GIT_REMOTEPORT, name); return URI.create(serverUrl); }
if (!"master".equalsIgnoreCase(git.getRepository().getBranch())) { git.checkout() .setCreateBranch(true) .setName("master") if (!branch.equalsIgnoreCase(git.getRepository().getBranch())) { boolean create = true; for (Ref ref : git.branchList().call()) { git.add() .addFilepattern(relative) .call(); git.commit() .setAuthor("clement", "clement@apache.org") .setCommitter("clement", "clement@apache.org") .setMessage("Add " + relative) .call();
private static void checkoutExistingBranchOrCreateOrphan(Git git, boolean isLocalOnly, String username, String password, String branch) throws IOException, GitAPIException { if (!isLocalOnly) { fetch(git, username, password); } // need to checkout branch ? if (!branch.equals(git.getRepository().getBranch())) { // HEAD is needed for creating a branch try { git.log().setMaxCount(1).call(); } catch (NoHeadException e) { // no HEAD - commit for creating a HEAD git.add().addFilepattern(".").call(); git.commit().setCommitter("a4c-bot", "a4c-bot@robot.org").setMessage("initial commit").call(); } // checkout branch CheckoutCommand checkoutCommand = git.checkout(); checkoutCommand.setName(branch); if (!branchExistsLocally(git, branch)) { checkoutCommand.setCreateBranch(true); String fullReference = getFullBranchReference(git, branch); boolean existRemotely = !fullReference.isEmpty(); if (existRemotely) { checkoutCommand.setStartPoint(getFullBranchReference(git, branch)); } else { checkoutCommand.setOrphan(true); } } checkoutCommand.call(); } }
remoteRepo.create(true); Git gitForPush = Git.cloneRepository().setURI(remoteRepo.getDirectory().getAbsolutePath()).setDirectory(cloneDir).call(); gitForPush.commit().setMessage("First commit").call(); RefSpec masterRefSpec = new RefSpec("master"); gitForPush.push().setRemote("origin").setRefSpecs(masterRefSpec).call(); + ConfigurationKeys.GIT_MONITOR_REPO_URI, remoteRepo.getDirectory().getAbsolutePath()) .addPrimitive(GitFlowGraphMonitor.GIT_FLOWGRAPH_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_REPO_DIR, TESTDIR + "/git-flowgraph") .addPrimitive(GitFlowGraphMonitor.GIT_FLOWGRAPH_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_POLLING_INTERVAL, 5) gitForPush.add().addFilepattern(formNodeFilePath(flowGraphDir, nodeDir.getName(), nodeFile.getName())).call(); gitForPush.commit().setMessage("Node commit").call(); gitForPush.push().setRemote("origin").setRefSpecs(masterRefSpec).call();
public Repository createCommit(File srcFolder, String applicationName) throws IOException, GitAPIException { Repository repository = repositoryService.createRepository(new Repository().setName(applicationName)); String cloneUrl = repository.getCloneUrl(); InitCommand init = new InitCommand(); init.setDirectory(srcFolder); init.setBare(false); Git git = init.call(); StoredConfig config = git.getRepository().getConfig(); config.setString("remote", "origin", "url", cloneUrl); config.save(); UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider(accessToken, ""); git.add().addFilepattern(".").call(); git.commit().setMessage(COMMIT_MESSAGE).call(); git.push().setCredentialsProvider(user).call(); return repository; } }
String remoteBranchPath = Utils.getCompleteGithubRepoUrl(prInformation.getOtherRepo().getFullName()); RemoteAddCommand remoteBranchCommand = git.remoteAdd(); remoteBranchCommand.setName("PR"); remoteBranchCommand.setUri(new URIish(remoteBranchPath)); remoteBranchCommand.call(); git.fetch().setRemote("PR").call(); this.gitResetPaths(commitHeadSha, paths, git.getRepository().getDirectory().getParentFile()); git.commit().setMessage("Undo changes on source code").setAuthor(this.getCommitterIdent()).setCommitter(this.getCommitterIdent()).call(); } else { git.checkout().setName(commitHeadSha).call(); RevWalk revwalk = new RevWalk(git.getRepository()); RevCommit revCommitBase = revwalk.lookupCommit(git.getRepository().resolve(commitBaseSha));
WrongRepositoryStateException, GitAPIException, StopTaskException { Context context = SGitApplication.getContext(); StoredConfig config = repo.getGit().getRepository().getConfig(); String committerEmail = config.getString("user", null, "email"); String committerName = config.getString("user", null, "name"); throw new Exception("Please include a commit message"); CommitCommand cc = repo.getGit().commit() .setCommitter(committerName, committerEmail).setAll(stageAll) .setAmend(isAmend).setMessage(msg); if (authorName != null && authorEmail != null) { cc.setAuthor(authorName, authorEmail); cc.call(); repo.updateLatestCommitInfo();
Status status = git.status().call(); Repository repository = git.getRepository(); File repoDir = repository.getDirectory().getParentFile(); if (!status.isClean()) AddCommand add = git.add(); add.addFilepattern(pomPath); add.call(); git.commit().setMessage(message).call();