version not being updated on first request after update (including due to hard resets)
New remote branches New remote tags — handling a null ref in should pull no longer needed. — has added benefit of ensuring the local repo is current in case of git failure. Returns version for tags (version was null before this change) New starter code for remote repo testing (where a lot of the complexity lies)
This commit is contained in:
@@ -24,10 +24,20 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jgit.api.*;
|
||||
import org.eclipse.jgit.api.CheckoutCommand;
|
||||
import org.eclipse.jgit.api.CloneCommand;
|
||||
import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
|
||||
import org.eclipse.jgit.api.FetchCommand;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.ListBranchCommand;
|
||||
import org.eclipse.jgit.api.ListBranchCommand.ListMode;
|
||||
import org.eclipse.jgit.api.MergeCommand;
|
||||
import org.eclipse.jgit.api.MergeResult;
|
||||
import org.eclipse.jgit.api.ResetCommand;
|
||||
import org.eclipse.jgit.api.ResetCommand.ResetType;
|
||||
import org.eclipse.jgit.api.Status;
|
||||
import org.eclipse.jgit.api.StatusCommand;
|
||||
import org.eclipse.jgit.api.TransportCommand;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.api.errors.RefNotFoundException;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
@@ -157,10 +167,12 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
|
||||
try {
|
||||
git = createGitClient();
|
||||
if (shouldPull(git)) {
|
||||
fetch(git, label);
|
||||
FetchResult fetchResult = fetch(git, label);
|
||||
//checkout after fetch so we can get any new branches, tags, ect.
|
||||
checkout(git, label);
|
||||
if(isBranch(git, label)) {
|
||||
merge(git, label);
|
||||
//merge results from fetch
|
||||
MergeResult mergeResult = merge(git, label);
|
||||
if (!isClean(git)) {
|
||||
logger.warn("The local repository is dirty. Resetting it to origin/"
|
||||
+ label + ".");
|
||||
@@ -170,6 +182,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
|
||||
|
||||
}
|
||||
else{
|
||||
//nothing to update so just checkout
|
||||
checkout(git, label);
|
||||
}
|
||||
//always return what is currently HEAD as the version
|
||||
@@ -328,29 +341,6 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assumes we are on a tracking branch (should be safe)
|
||||
*/
|
||||
private void pull(Git git, String label, Ref ref) {
|
||||
PullCommand pull = git.pull();
|
||||
setTimeout(pull);
|
||||
try {
|
||||
if (hasText(getUsername())) {
|
||||
setCredentialsProvider(pull);
|
||||
}
|
||||
pull.call();
|
||||
}
|
||||
catch (Exception e) {
|
||||
this.logger
|
||||
.warn("Could not pull remote for " + label + " (current ref=" + ref
|
||||
+ "), remote: "
|
||||
+ git.getRepository().getConfig().getString("remote",
|
||||
"origin", "url")
|
||||
+ ", cause: (" + e.getClass().getSimpleName() + ") "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private Git createGitClient() throws IOException, GitAPIException {
|
||||
if (new File(getBasedir(), ".git").exists()) {
|
||||
return openGitRepository();
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.io.File;
|
||||
|
||||
/**
|
||||
* Class that holds objects that can be used for testing
|
||||
* @author Ryan Lynch
|
||||
*/
|
||||
public class JGitConfigServerTestData {
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ import org.springframework.util.StreamUtils;
|
||||
* @author Dave Syer
|
||||
* @author Roy Clarkson
|
||||
* @author Daniel Lavoie
|
||||
* @author Ryan Lynch
|
||||
*/
|
||||
public class JGitEnvironmentRepositoryIntegrationTests {
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.eclipse.jgit.api.CloneCommand;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.Status;
|
||||
import org.eclipse.jgit.api.StatusCommand;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.lib.StoredConfig;
|
||||
import org.eclipse.jgit.util.FileUtils;
|
||||
@@ -36,7 +35,6 @@ import org.springframework.core.env.StandardEnvironment;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
|
||||
Reference in New Issue
Block a user