@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"); }
/** * Create a new RefSpec with a different force update setting. * * @param forceUpdate * new value for force update in the returned instance. * @return a new RefSpec with force update as specified. */ public RefSpec setForceUpdate(boolean forceUpdate) { final RefSpec r = new RefSpec(this); r.force = forceUpdate; return r; }
this.gitForPush.push().setRemote("origin").setRefSpecs(new RefSpec("master")).call();
RefSpec masterRefSpec = new RefSpec("master"); gitForPush.push().setRemote("origin").setRefSpecs(masterRefSpec).call();
/** {@inheritDoc} */ @Override @NonNull public List<RefSpec> getRefSpecs(Config config, String section, String subsection, String name) { String[] values = config.getStringList(section, subsection, name); List<RefSpec> result = new ArrayList<>(values.length); for (String spec : values) { result.add(new RefSpec(spec)); } return result; } }
/** * Add a reference to push. * * @param ref * the source reference. The remote name will match. * @return {@code this}. */ public PushCommand add(Ref ref) { refSpecs.add(new RefSpec(ref.getLeaf().getName())); return this; }
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; }
/** * Expand this specification to exactly match a ref name. * <p> * Callers must first verify the passed ref name matches this specification, * otherwise expansion results may be unpredictable. * * @param r * a ref name that matched our source specification. Could be a * wildcard also. * @return a new specification expanded from provided ref name. Result * specification is wildcard if and only if provided ref name is * wildcard. * @throws java.lang.IllegalStateException * when the RefSpec was constructed with wildcard mode that * doesn't require matching wildcards. */ public RefSpec expandFromSource(String r) { if (allowMismatchedWildcards != WildcardMode.REQUIRE_MATCH) { throw new IllegalStateException( JGitText.get().invalidExpandWildcard); } return isWildcard() ? new RefSpec(this).expandFromSourceImp(r) : this; }
/** * Expand this specification to exactly match a ref name. * <p> * Callers must first verify the passed ref name matches this specification, * otherwise expansion results may be unpredictable. * * @param r * a ref name that matched our destination specification. Could * be a wildcard also. * @return a new specification expanded from provided ref name. Result * specification is wildcard if and only if provided ref name is * wildcard. * @throws java.lang.IllegalStateException * when the RefSpec was constructed with wildcard mode that * doesn't require matching wildcards. */ public RefSpec expandFromDestination(String r) { if (allowMismatchedWildcards != WildcardMode.REQUIRE_MATCH) { throw new IllegalStateException( JGitText.get().invalidExpandWildcard); } return isWildcard() ? new RefSpec(this).expandFromDstImp(r) : this; }
/** * Add a reference to push. * * @param nameOrSpec * any reference name, or a reference specification. * @return {@code this}. * @throws JGitInternalException * the reference name cannot be resolved. */ public PushCommand add(String nameOrSpec) { if (0 <= nameOrSpec.indexOf(':')) { refSpecs.add(new RefSpec(nameOrSpec)); } else { Ref src; try { src = repo.findRef(nameOrSpec); } catch (IOException e) { throw new JGitInternalException( JGitText.get().exceptionCaughtDuringExecutionOfPushCommand, e); } if (src != null) add(src); } return this; }
/** * 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; }
/** * Create a new RefSpec with a different source name setting. * * @param source * new value for source in the returned instance. * @return a new RefSpec with source as specified. * @throws java.lang.IllegalStateException * There is already a destination configured, and the wildcard * status of the existing destination disagrees with the * wildcard status of the new source. */ public RefSpec setSource(String source) { final RefSpec r = new RefSpec(this); r.srcName = checkValid(source); if (isWildcard(r.srcName) && r.dstName == null) throw new IllegalStateException(JGitText.get().destinationIsNotAWildcard); if (isWildcard(r.srcName) != isWildcard(r.dstName)) throw new IllegalStateException(JGitText.get().sourceDestinationMustMatch); return r; }
/** * Create a new RefSpec with a different destination name setting. * * @param destination * new value for destination in the returned instance. * @return a new RefSpec with destination as specified. * @throws java.lang.IllegalStateException * There is already a source configured, and the wildcard status * of the existing source disagrees with the wildcard status of * the new destination. */ public RefSpec setDestination(String destination) { final RefSpec r = new RefSpec(this); r.dstName = checkValid(destination); if (isWildcard(r.dstName) && r.srcName == null) throw new IllegalStateException(JGitText.get().sourceIsNotAWildcard); if (isWildcard(r.srcName) != isWildcard(r.dstName)) throw new IllegalStateException(JGitText.get().sourceDestinationMustMatch); return r; }
/** * 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; }
private void wantTag(Ref r) throws TransportException { want(r, new RefSpec().setSource(r.getName()) .setDestination(r.getName()).setForceUpdate(true)); }
/** * fetch tags from remote * @param path * @param remoteName * @return * @throws GitException */ public static Path fetchTags(Path path, String remoteName) throws GitException { try (Git git = Git.open(path.toFile())) { git.fetch() .setRemote(remoteName) .setRefSpecs(new RefSpec("refs/tags/*:refs/tags/*")) .setTagOpt(TagOpt.FETCH_TAGS) .call(); } catch (Throwable throwable) { throw new GitException("fetch tags error", throwable); } return path; }
/** * {@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); } }
Ref head = repo.exactRef(Constants.HEAD); if (head != null && head.isSymbolic()) refSpecs.add(new RefSpec(head.getLeaf().getName()));
public void modifyText(ModifyEvent e) { if (!specString.isFocusControl() || getSpec().toString().equals(specString.getText())) return; setSpec(new RefSpec(specString.getText())); } });