Skip to content

Commit

Permalink
Fixed JENKINS-24844
Browse files Browse the repository at this point in the history
This is a bug that prevented repository walking when used on a remote
machine. This broke builds on all slaves.
  • Loading branch information
MadsNielsen committed Sep 24, 2014
1 parent 97713c7 commit 38f8335
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 215 deletions.
Expand Up @@ -12,12 +12,18 @@
import hudson.model.BuildListener;
import hudson.plugins.git.Branch;
import hudson.plugins.git.util.BuildData;
import hudson.remoting.VirtualChannel;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.jenkinsci.plugins.gitclient.Git;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.jenkinsci.plugins.gitclient.RepositoryCallback;
import org.jenkinsci.plugins.pretestedintegration.AbstractSCMBridge;
import org.jenkinsci.plugins.pretestedintegration.Commit;
import org.jenkinsci.plugins.pretestedintegration.exceptions.IntegationFailedExeception;
Expand Down Expand Up @@ -54,6 +60,7 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener

try {
client = Git.with(listener, build.getEnvironment(listener)).in(build.getWorkspace()).getClient();

for(Branch b : client.getRemoteBranches()) {
if(b.getName().equals(gitDataBranch.getName())) {
found = true;
Expand Down Expand Up @@ -83,8 +90,8 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener

listener.getLogger().println( String.format( "Preparing to merge changes in commit %s to integration branch %s", (String) commit.getId(), gitbridge.getBranch() ) );
try {
String commitMessage = GitUtils.getCommitMessageUsingSHA1(client.getRepository(), gitDataBranch.getSHA1());


String commitMessage = client.withRepository(new FindCommitMessageCallback(listener, gitDataBranch.getSHA1()));
exitCode = gitbridge.git(build, launcher, listener, out, "merge","-m", String.format("%s\n[%s]", commitMessage, gitDataBranch.getName()), (String) commit.getId(), "--no-ff");
} catch (Exception ex) {
throw new IntegationFailedExeception(ex);
Expand Down
@@ -0,0 +1,38 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.jenkinsci.plugins.pretestedintegration.scm.git;

import hudson.model.TaskListener;
import hudson.remoting.VirtualChannel;
import java.io.IOException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;

/**
*
* @author Mads
*
* Used in con
*/
public class FindCommitMessageCallback extends RepositoryListenerAwareCallback<String> {

public final ObjectId id;

public FindCommitMessageCallback(TaskListener listener, final ObjectId id) {
super(listener);
this.id = id;
}

@Override
public String invoke(Repository repo, VirtualChannel channel) throws IOException, InterruptedException {
RevWalk walk = new RevWalk(repo);
RevCommit commit = walk.parseCommit(id);
walk.dispose();
return commit.getFullMessage();
}
}

This file was deleted.

@@ -0,0 +1,28 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.jenkinsci.plugins.pretestedintegration.scm.git;

import hudson.model.TaskListener;
import hudson.remoting.VirtualChannel;
import java.io.IOException;
import org.eclipse.jgit.lib.Repository;
import org.jenkinsci.plugins.gitclient.RepositoryCallback;

/**
*
* @author Mads
*/
public abstract class RepositoryListenerAwareCallback<T> implements RepositoryCallback<T> {

public final TaskListener listener;

public RepositoryListenerAwareCallback(TaskListener listener) {
this.listener = listener;
}

public abstract T invoke(Repository repo, VirtualChannel channel) throws IOException, InterruptedException;

}
Expand Up @@ -77,12 +77,12 @@ public void integrate(AbstractBuild<?,?> build, Launcher launcher, BuildListener
}

try {
String commitMessage = GitUtils.getCommitMessageUsingSHA1(client.getRepository(), gitDataBranch.getSHA1());
String commitMessage = client.withRepository(new FindCommitMessageCallback(listener, gitDataBranch.getSHA1()));

exitCode = gitbridge.git(build, launcher, listener, out, "merge", "--squash", gitDataBranch.getName());
exitCodeCommit = gitbridge.git(build, launcher, listener, out, "commit", "-C", gitDataBranch.getName());

listener.getLogger().println( String.format( "Commit message:\n%s", commitMessage));
listener.getLogger().println( String.format( "Commit message:%n%s", commitMessage));
} catch (Exception ex) { /*Handled below */ }

if (exitCode != 0) {
Expand Down

This file was deleted.

0 comments on commit 38f8335

Please sign in to comment.