Refine search
@Test (dependsOnMethods = "testDelete") public void testGitCreate() throws Exception { // push a new config file File testFlowFile = new File(GIT_CLONE_DIR + "/gobblin-config/testGroup/testFlow.pull"); testFlowFile.getParentFile().mkdirs(); Files.write("flow.name=testFlow\nflow.group=testGroup\nparam1=value20\n", testFlowFile, Charsets.UTF_8); Collection<Spec> specs = this.gobblinServiceManager.flowCatalog.getSpecs(); Assert.assertTrue(specs.size() == 0); // add, commit, push this.gitForPush.add().addFilepattern("gobblin-config/testGroup/testFlow.pull").call(); this.gitForPush.commit().setMessage("second commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(new RefSpec("master")).call(); // polling is every 5 seconds, so wait twice as long and check TimeUnit.SECONDS.sleep(10); specs = this.gobblinServiceManager.flowCatalog.getSpecs(); Assert.assertTrue(specs.size() == 1); FlowSpec spec = (FlowSpec) (specs.iterator().next()); Assert.assertEquals(spec.getUri(), new URI("gobblin-flow:/testGroup/testFlow")); Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_NAME_KEY), "testFlow"); Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_GROUP_KEY), "testGroup"); Assert.assertEquals(spec.getConfig().getString("param1"), "value20"); }
private void wantTag(Ref r) throws TransportException { want(r, new RefSpec().setSource(r.getName()) .setDestination(r.getName()).setForceUpdate(true)); }
/** * {@inheritDoc} * <p> * Executes the {@code remote add} command with all the options and * parameters collected by the setter methods of this class. */ @Override public RemoteConfig call() throws GitAPIException { checkCallable(); try { StoredConfig config = repo.getConfig(); RemoteConfig remote = new RemoteConfig(config, name); RefSpec refSpec = new RefSpec(); refSpec = refSpec.setForceUpdate(true); refSpec = refSpec.setSourceDestination(Constants.R_HEADS + "*", //$NON-NLS-1$ Constants.R_REMOTES + name + "/*"); //$NON-NLS-1$ remote.addFetchRefSpec(refSpec); remote.addURI(uri); remote.update(config); config.save(); return remote; } catch (IOException | URISyntaxException e) { throw new JGitInternalException(e.getMessage(), e); } }
private List<RefSpec> calculateRefSpecs(boolean fetchAll, String dst) { RefSpec wcrs = new RefSpec(); wcrs = wcrs.setForceUpdate(true); wcrs = wcrs.setSourceDestination(Constants.R_HEADS + '*', dst); List<RefSpec> specs = new ArrayList<>(); if (!fetchAll) { for (String selectedRef : branchesToClone) { if (wcrs.matchSource(selectedRef)) { specs.add(wcrs.expandFromSource(selectedRef)); } } } else { specs.add(wcrs); } return specs; }
/** * Create a new RefSpec with a different source/destination name setting. * * @param source * new value for source in the returned instance. * @param destination * new value for destination in the returned instance. * @return a new RefSpec with destination as specified. * @throws java.lang.IllegalArgumentException * The wildcard status of the new source disagrees with the * wildcard status of the new destination. */ public RefSpec setSourceDestination(final String source, final String destination) { if (isWildcard(source) != isWildcard(destination)) throw new IllegalStateException(JGitText.get().sourceDestinationMustMatch); final RefSpec r = new RefSpec(this); r.wildcard = isWildcard(source); r.srcName = source; r.dstName = destination; return r; }
ObjectId since = fork.getRepository().resolve("HEAD^{commit}"); ObjectId to = fork.getRepository().resolve(gitPatchRepository.getMainBranchName() + "^{commit}"); Iterable<RevCommit> mainChanges = fork.log().addRange(since, to).call(); List<RevCommit> userChanges = new LinkedList<>(); fork.tagDelete().setTags(entry.getKey()).call(); fork.push() .setRefSpecs(new RefSpec() .setSource(null) .setDestination("refs/tags/" + entry.getKey())) .call();
RevCommit c1 = new RevWalk(fork.getRepository()) .parseCommit(fork.getRepository().resolve(currentBaseline.getTagName() + "^{commit}")); RevCommit c2 = new RevWalk(fork.getRepository()) .parseCommit(fork.getRepository().resolve("HEAD")); RevCommit to = c2; fork.push() .setRefSpecs(new RefSpec() .setSource(null) .setDestination("refs/tags/" + currentBaseline.getTagName())) .call(); fork.tagDelete().setTags(entry.getKey()).call(); fork.push() .setRefSpecs(new RefSpec() .setSource(null) .setDestination("refs/tags/" + entry.getKey())) .call(); fork.push() .setRefSpecs(new RefSpec() .setSource(null) .setDestination(String.format("refs/tags/%s", patchTagName))) .call();
Set<String> changeds = git.status().call().getModified(); if ( changeds.isEmpty() ) AddCommand add = git.add(); for ( String changed : changeds ) UserInfo committer = getCommitter( repo, git ); CommitCommand command = git.commit().setMessage( message ).setAuthor( author.name, author.email ); command.setCommitter( committer.name, committer.email ); RevCommit commitRev = command.call(); branch = git.getRepository().getBranch(); RefSpec refSpec = new RefSpec( Constants.R_HEADS + branch + ":" + Constants.R_HEADS + branch ); getLogger().info( "push changes to remote... " + refSpec.toString() ); JGitUtils.push( getLogger(), git, (GitScmProviderRepository) repo, refSpec );
protected void cleanupBranchesIfNeeded(String branchToCheckout, String... branchesToDelete) throws GitAPIException, JGitFlowGitAPIException { if (!keepBranch) { git.checkout().setName(branchToCheckout).call(); for (String branchToDelete : branchesToDelete) { if (GitHelper.localBranchExists(git, branchToDelete)) { reporter.infoText(getCommandName(), "deleting local branch: " + branchToDelete); git.branchDelete().setForce(forceDeleteBranch).setBranchNames(branchToDelete).call(); } if (isPush() && GitHelper.remoteBranchExists(git, branchToDelete)) { reporter.infoText(getCommandName(), "pushing deleted branch: :" + branchToDelete); RefSpec deleteSpec = new RefSpec().setSource(null).setDestination(Constants.R_HEADS + branchToDelete); git.push().setRemote(Constants.DEFAULT_REMOTE_NAME).setRefSpecs(deleteSpec).call(); } } } }
public static void deleteBranch(Path targetDirectory, String branch, boolean deleteRemoteBranch){ Git repository = null; try { repository = Git.open(targetDirectory.toFile()); //delete locally if (branchExistsLocally(repository, branch)) { // is current branch? if(repository.getRepository().getBranch().equals(branch)){ checkoutExistingBranchOrCreateOrphan(repository, true, null,null, "tmp"); } repository.branchDelete().setForce(true).setBranchNames("refs/heads/" + branch).call(); } // delete remote branch if(deleteRemoteBranch){ RefSpec refSpec = new RefSpec() .setSource(null) .setDestination("refs/heads/" + branch); repository.push().setRefSpecs(refSpec).setRemote("origin").call(); } } catch (IOException | GitAPIException e) { throw new GitException("Error while deleting branch <" + branch + ">", e); } finally { close(repository); } }
@Override protected Git getGitRepo() throws Exception { if (stagingDirectory.exists() && new File(stagingDirectory, "HEAD").exists()) { Git git = Git.open(stagingDirectory); git.fetch().setRemote(getRemoteUrl(null, null)).setProgressMonitor(new TextProgressMonitor()).setRefSpecs(new RefSpec("refs/heads/master")).call(); } else { Git.cloneRepository() .setURI(getRemoteUrl(null, null)) .setProgressMonitor(new TextProgressMonitor()) .setDirectory(stagingDirectory) .setNoCheckout(true) .setBare(true) .call(); } Repository r = null; RepositoryBuilder b = new RepositoryBuilder().setGitDir(stagingDirectory).setWorkTree(sourceDirectory); r = b.build(); final Git git = Git.wrap(r); return git; }
@Override public void push(Git git, String branch) throws GitAPIException { git.push() .setRemote("origin") .setRefSpecs(new RefSpec(branch)) .setPushTags() .setForce(true) .call(); // in fabric env we synchronize changes with "local" git repo, which will be then (from fabric-agent) // pushed further to cluster's git repo if (master && mainRepository != null && !branch.startsWith("patch-") && !branch.equals(getMainBranchName())) { // we don't push "patch-*" branches to central repo (we push "patches-*") // getMainBranchName() is used to track current container's history mainRepository.push() .setRemote("origin") .setRefSpecs(new RefSpec(branch)) .setPushTags() .setForce(true) .call(); } }
@Override public Iterable<PushResult> pushPatchBranches() throws GitAPIException { List<Ref> localBranches = mainRepository.branchList().call(); List<RefSpec> toPush = new LinkedList<>(); for (Ref ref : localBranches) { if (ref.getName().startsWith("refs/heads/patches-")) { toPush.add(new RefSpec(ref.getName())); } } return mainRepository.push().setRefSpecs(toPush).setPushTags().call(); }
/** * Set a remote repository path. * * @param repositoryDirectory The directory in which the git repo exists. * @param remoteName The name of the remote (i.e. 'origin') * @param remoteUrl The url of the repository. */ public static void setRemote(Path repositoryDirectory, String remoteName, String remoteUrl) { Git git = null; try { git = Git.open(repositoryDirectory.toFile()); StoredConfig config = git.getRepository().getConfig(); config.unsetSection("remote", remoteName); RemoteConfig remoteConfig = new RemoteConfig(config, remoteName); remoteConfig.addURI(new URIish(remoteUrl)); remoteConfig.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + remoteName + "/*")); remoteConfig.update(config); config.save(); } catch (URISyntaxException | IOException e) { throw new GitException("Unable to set the remote repository", e); } finally { close(git); } }
public Ref fetchNotesRef(Git git) throws IOException, GitAPIException { Ref ref = git.getRepository().findRef(GIT_NOTES_REF); if (areNotesInRemote(git)) { git.fetch().setRemote("origin") .setDryRun(false) .setRefSpecs(new RefSpec(GIT_NOTES_REF + ":" + GIT_NOTES_REF)) .call(); } return ref; }
/** * Push code to remote repo * * @param path * @param remote * @param branchOrTag * @return * @throws GitException */ public static Path push(Path path, String remote, String branchOrTag) throws GitException { try (Git git = Git.open(path.toFile())) { git.push() .setRemote(remote) .setRefSpecs(new RefSpec(branchOrTag)) .call(); } catch (Throwable throwable) { throw new GitException("Fail to Push ", throwable); } return path; }
public Void call(Git git, GitContext context) throws Exception { removeVersionFromCaches(versionId); GitHelpers.removeBranch(git, versionId); git.push().setTimeout(gitTimeout) .setCredentialsProvider(getCredentialsProvider()) .setRefSpecs(new RefSpec().setSource(null).setDestination("refs/heads/" + versionId)) .call(); return null; } };
private void fetch() throws GitAPIException { for (SubtreeConfig config : subtreeConfigs) { RefSpec branchesSpec = new RefSpec( "refs/heads/*:refs/heads/original/" + config.getRemoteName() + "/*"); RefSpec tagsSpec = new RefSpec("refs/tags/*:refs/tags/original/" + config.getRemoteName() + "/*"); Git git = new Git(repository); git.fetch().setRemote(config.getFetchUri().toPrivateString()) .setRefSpecs(branchesSpec, tagsSpec).call(); } }