Skip to content

Making repository lock failure retryable #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/git/IGitAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public interface IGitAPI extends GitClient {
List<ObjectId> revListBranch(String branchId) throws GitException, InterruptedException;
List<Tag> getTagsOnCommit(String revName) throws GitException, IOException, InterruptedException;
void changelog(String revFrom, String revTo, OutputStream fos) throws GitException, InterruptedException;
void checkoutBranch(String branch, String commitish) throws GitException, InterruptedException;
void checkoutBranch(String branch, String commitish) throws IOException, GitException, InterruptedException;
ObjectId mergeBase(ObjectId sha1, ObjectId sha12) throws InterruptedException;
List<String> showRevision(Revision r) throws GitException, InterruptedException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ public void checkout(String ref, String branch) throws GitException, Interrupted
launchCommand("checkout", "-b", branch, ref);
}

public void checkoutBranch(String branch, String ref) throws GitException, InterruptedException {
public void checkoutBranch(String branch, String ref) throws IOException, GitException, InterruptedException {
try {
// First, checkout to detached HEAD, so we can delete the branch.
checkout(ref);
Expand All @@ -891,7 +891,8 @@ public void checkoutBranch(String branch, String ref) throws GitException, Inter
checkout(ref, branch);
}
} catch (GitException e) {
throw new GitException("Could not checkout " + branch + " with start point " + ref, e);
// Throw IOException so the retry will be able to catch it
throw new IOException("Could not checkout " + branch + " with start point " + ref, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public interface GitClient {
* For compatibility reasons, the order of the parameter is different from {@link #checkout(String, String)}.
* @since 1.0.6
*/
void checkoutBranch(String branch, String ref) throws GitException, InterruptedException;
void checkoutBranch(String branch, String ref) throws IOException, GitException, InterruptedException;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.jgit.api.ResetCommand;
import org.eclipse.jgit.api.ShowNoteCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.diff.RenameDetector;
Expand Down Expand Up @@ -177,7 +178,7 @@ public void checkout(String ref, String branch) throws GitException {
}
}

public void checkoutBranch(String branch, String ref) throws GitException {
public void checkoutBranch(String branch, String ref) throws IOException, GitException {
try {
RefUpdate refUpdate = db().updateRef(R_HEADS + branch);
refUpdate.setNewObjectId(db().resolve(ref));
Expand All @@ -194,6 +195,9 @@ public void checkoutBranch(String branch, String ref) throws GitException {
checkout(ref);
} catch (IOException e) {
throw new GitException("Could not checkout " + branch + " with start point " + ref, e);
} catch (JGitInternalException e) {
// Throw IOException so the retry will be able to catch it
throw new IOException(e.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public void checkout(String ref, String branch) throws GitException, Interrupted
proxy.checkout(ref, branch);
}

public void checkoutBranch(String branch, String ref) throws GitException, InterruptedException {
public void checkoutBranch(String branch, String ref) throws IOException, GitException, InterruptedException {
proxy.checkoutBranch(branch, ref);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,4 +733,18 @@ private String formatBranches(List<Branch> branches) {
}
return Util.join(names,",");
}

public void test_checkoutBranchFailure() throws Exception {
w = clone(localMirror());
File lock = new File(w.repo, ".git/index.lock");
try {
FileUtils.touch(lock);
w.git.checkoutBranch("somebranch", "master");
fail();
} catch (IOException e) {
// expected
} finally {
lock.delete();
}
}
}