use of com.google.copybara.GeneralOptions in project copybara by google.
the class GerritDestination method newGerritDestination.
static GerritDestination newGerritDestination(Options options, String url, String fetch, String pushToRefsFor, boolean submit, ChangeIdPolicy changeIdPolicy) {
GeneralOptions generalOptions = options.get(GeneralOptions.class);
if (pushToRefsFor.isEmpty()) {
pushToRefsFor = fetch;
}
GerritOptions gerritOptions = options.get(GerritOptions.class);
String push;
if (submit) {
push = pushToRefsFor;
} else {
push = Strings.isNullOrEmpty(gerritOptions.gerritTopic) ? String.format("refs/for/%s", pushToRefsFor) : String.format("refs/for/%s%%topic=%s", pushToRefsFor, gerritOptions.gerritTopic);
}
GitDestinationOptions destinationOptions = options.get(GitDestinationOptions.class);
return new GerritDestination(new GitDestination(url, fetch, push, destinationOptions, options.get(GitOptions.class), generalOptions, /*skipPush=*/
false, new CommitGenerator(gerritOptions, url, destinationOptions.getCommitter(), generalOptions.console(), changeIdPolicy), new GerritProcessPushOutput(generalOptions.console()), NO_GIT_DESTINATION_INTEGRATES), submit);
}
use of com.google.copybara.GeneralOptions in project copybara by google.
the class GitRepoTypeTest method setup.
@Before
public void setup() throws Exception {
repoGitDir = Files.createTempDirectory("testRepo");
fileRepoDir = Files.createTempDirectory("fileRepo");
// We mock by default to avoid accidental network calls.
testRepo = new GitRepository(repoGitDir, null, /*verbose=*/
true, getGitEnv()) {
@Override
public GitRevision fetchSingleRef(String url, String ref) throws RepoException {
interceptedFetches.add(new String[] { url, ref });
return new GitRevision(this, Strings.repeat("0", 40));
}
};
testRepo.init();
prepareFileRepo();
console = new TestingConsole();
generalOptions = new OptionsBuilder().setConsole(console).build().get(GeneralOptions.class);
}
use of com.google.copybara.GeneralOptions in project copybara by google.
the class GithubPROrigin method newReader.
@Override
public Reader<GitRevision> newReader(Glob originFiles, Authoring authoring) throws ValidationException {
return new ReaderImpl(url, originFiles, authoring, gitOptions, gitOriginOptions, generalOptions, /*includeBranchCommitLogs=*/
false, submoduleStrategy, firstParent) {
/**
* Disable rebase since this is controlled by useMerge field.
*/
@Override
protected void maybeRebase(GitRepository repo, GitRevision ref, Path workdir) throws RepoException, CannotResolveRevisionException {
}
@Override
public Optional<Baseline<GitRevision>> findBaseline(GitRevision startRevision, String label) throws RepoException, ValidationException {
if (!baselineFromBranch) {
return super.findBaseline(startRevision, label);
}
return findBaselinesWithoutLabel(startRevision, /*limit=*/
1).stream().map(e -> new Baseline<>(e.getSha1(), e)).findFirst();
}
@Override
public ImmutableList<GitRevision> findBaselinesWithoutLabel(GitRevision startRevision, int limit) throws RepoException, ValidationException {
String baseline = startRevision.associatedLabels().get(GITHUB_BASE_BRANCH_SHA1);
Preconditions.checkNotNull(baseline, "%s label should be present in %s", GITHUB_BASE_BRANCH_SHA1, startRevision);
GitRevision baselineRev = getRepository().resolveReference(baseline);
// Don't skip the first change as it is already the baseline
BaselinesWithoutLabelVisitor<GitRevision> visitor = new BaselinesWithoutLabelVisitor<>(originFiles, limit, /*skipFirst=*/
false);
visitChanges(baselineRev, visitor);
return visitor.getResult();
}
@Override
public Endpoint getFeedbackEndPoint() {
return new GitHubEndPoint(githubOptions, url);
}
/**
* Deal with the case of useMerge. We have a new commit (the merge) and first-parent from that
* commit doesn't work for this case.
*/
@Override
public ChangesResponse<GitRevision> changes(@Nullable GitRevision fromRef, GitRevision toRef) throws RepoException {
if (!useMerge) {
return super.changes(fromRef, toRef);
}
GitLogEntry merge = Iterables.getOnlyElement(getRepository().log(toRef.getSha1()).withLimit(1).run());
// Fast-forward merge
if (merge.getParents().size() == 1) {
return super.changes(fromRef, toRef);
}
// HEAD of the Pull Request
GitRevision gitRevision = merge.getParents().get(1);
ChangesResponse<GitRevision> prChanges = super.changes(fromRef, gitRevision);
// origin_files
if (prChanges.isEmpty()) {
return prChanges;
}
try {
return ChangesResponse.forChanges(ImmutableList.<Change<GitRevision>>builder().addAll(prChanges.getChanges()).add(change(merge.getCommit())).build());
} catch (EmptyChangeException e) {
throw new RepoException("Error getting the merge commit information: " + merge, e);
}
}
@Nullable
@Override
public String getGroupIdentity(GitRevision rev) throws RepoException {
return rev.associatedLabels().get(GITHUB_PR_NUMBER_LABEL);
}
};
}
use of com.google.copybara.GeneralOptions in project copybara by google.
the class GerritOptionsTest method setup.
@Before
public void setup() {
Supplier<GeneralOptions> generalOptionsSupplier = Suppliers.ofInstance(new GeneralOptions(FileSystems.getDefault(), /*verbose=*/
true, LogConsole.writeOnlyConsole(System.out, /*verbose=*/
true)));
options = new GerritOptions(generalOptionsSupplier, new GitOptions(generalOptionsSupplier));
jcommander = new JCommander(ImmutableList.of(options));
}
Aggregations