From dbccf9e5351f138e2c055f909ca1683844ad1e84 Mon Sep 17 00:00:00 2001 From: liolay <565055991@qq.com> Date: Thu, 1 Mar 2018 09:14:18 +0800 Subject: [PATCH 1/8] wrong value eval at ignoreLocalSshSettings (#892) when "spring.cloud.config.server.git.ignoreLocalSshSettings" is "true",there is a wrong value eval at ignoreLocalSshSettings to decide whether SshUri configured in "spring.cloud.config.server.git.repos" need be validate --- .../cloud/config/server/ssh/PrivateKeyValidator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ssh/PrivateKeyValidator.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ssh/PrivateKeyValidator.java index cd95a705..636f962f 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ssh/PrivateKeyValidator.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ssh/PrivateKeyValidator.java @@ -55,7 +55,7 @@ public class PrivateKeyValidator implements ConstraintValidator extractedProperties = sshPropertyValidator.extractRepoProperties(sshUriProperties); for (SshUri extractedProperty : extractedProperties) { - if (sshUriProperties.isIgnoreLocalSshSettings() && isSshUri(extractedProperty.getUri())) { + if (extractedProperty.isIgnoreLocalSshSettings() && isSshUri(extractedProperty.getUri())) { validationResults.add( isPrivateKeyPresent(extractedProperty, context) && isPrivateKeyFormatCorrect(extractedProperty, context)); From c385f8b42984f48322adfa7ae06021844e0c2e52 Mon Sep 17 00:00:00 2001 From: Taras Danylchuk Date: Thu, 22 Mar 2018 15:19:10 +0200 Subject: [PATCH 2/8] Added functionality for deleting untracked branches from local repo (#947) cherry-picked from https://github.com/spring-cloud/spring-cloud-config/pull/940 --- .../main/asciidoc/spring-cloud-config.adoc | 26 ++++ .../JGitEnvironmentRepository.java | 86 ++++++++++++- .../environment/JGitConfigServerTestData.java | 17 ++- ...EnvironmentRepositoryIntegrationTests.java | 37 ++++++ .../JGitEnvironmentRepositoryTests.java | 117 +++++++++++++++++- 5 files changed, 275 insertions(+), 8 deletions(-) diff --git a/docs/src/main/asciidoc/spring-cloud-config.adoc b/docs/src/main/asciidoc/spring-cloud-config.adoc index b2c37688..b32ddbb3 100644 --- a/docs/src/main/asciidoc/spring-cloud-config.adoc +++ b/docs/src/main/asciidoc/spring-cloud-config.adoc @@ -529,6 +529,32 @@ spring: NOTE: The default value for `force-pull` property is `false`. +===== Deleting untracked branches in Git Repositories + +As Spring Cloud Config Server has a clone of the remote git repository +after check-outing branch to local repo (e.g fetching properties by label) it will keep this branch +forever or till the next server restart (which creates new local repo). +So there could be a case when remote branch is deleted but local copy of it is still available for fetching. +And if Spring Cloud Config Server client service starts with `--spring.cloud.config.label=deletedRemoteBranch,master` +it will fetch properties from `deletedRemoteBranch` local branch, but not from `master`. + +In order to keep local repository branches clean and up to remote - `deleteUntrackedBranches` property could be set. +It will make Spring Cloud Config Server *force* delete untracked branches from local repository. +Example: + +[source,yaml] +---- +spring: + cloud: + config: + server: + git: + uri: https://github.com/spring-cloud-samples/config-repo + deleteUntrackedBranches: true + +---- + +NOTE: The default value for `deleteUntrackedBranches` property is `false`. ==== Version Control Backend Filesystem Use diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java index 1e7c33c5..6db6dbda 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java @@ -20,6 +20,9 @@ import static org.springframework.util.StringUtils.hasText; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -27,6 +30,7 @@ import java.util.Set; import org.eclipse.jgit.api.CheckoutCommand; import org.eclipse.jgit.api.CloneCommand; import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode; +import org.eclipse.jgit.api.DeleteBranchCommand; import org.eclipse.jgit.api.FetchCommand; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.ListBranchCommand; @@ -47,8 +51,10 @@ import org.eclipse.jgit.transport.CredentialsProvider; import org.eclipse.jgit.transport.FetchResult; import org.eclipse.jgit.transport.JschConfigSessionFactory; import org.eclipse.jgit.transport.OpenSshConfig.Host; +import org.eclipse.jgit.transport.ReceiveCommand; import org.eclipse.jgit.transport.SshSessionFactory; import org.eclipse.jgit.transport.TagOpt; +import org.eclipse.jgit.transport.TrackingRefUpdate; import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; import org.eclipse.jgit.util.FileUtils; import org.springframework.beans.factory.InitializingBean; @@ -56,7 +62,10 @@ import org.springframework.cloud.config.server.support.PassphraseCredentialsProv import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.io.UrlResource; import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; +import static java.lang.String.format; +import static org.eclipse.jgit.transport.ReceiveCommand.Type.DELETE; import com.jcraft.jsch.Session; @@ -75,6 +84,8 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository private static final String DEFAULT_LABEL = "master"; private static final String FILE_URI_PREFIX = "file:"; + private static final String LOCAL_BRANCH_REF_PREFIX = "refs/remotes/origin/"; + /** * Timeout (in seconds) for obtaining HTTP or SSH connection (if applicable). Default * 5 seconds. @@ -108,6 +119,11 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository private boolean forcePull; private boolean initialized; + /** + * Flag to indicate that the branch should be deleted locally if it's origin tracked branch was removed. + */ + private boolean deleteUntrackedBranches; + public JGitEnvironmentRepository(ConfigurableEnvironment environment) { super(environment); } @@ -161,6 +177,14 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository this.forcePull = forcePull; } + public boolean isDeleteUntrackedBranches() { + return deleteUntrackedBranches; + } + + public void setDeleteUntrackedBranches(boolean deleteUntrackedBranches) { + this.deleteUntrackedBranches = deleteUntrackedBranches; + } + @Override public synchronized Locations getLocations(String application, String profile, String label) { @@ -190,9 +214,11 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository try { git = createGitClient(); if (shouldPull(git)) { - fetch(git, label); - // checkout after fetch so we can get any new branches, tags, - // ect. + FetchResult fetchStatus = fetch(git, label); + if(deleteUntrackedBranches) { + deleteUntrackedLocalBranches(fetchStatus.getTrackingRefUpdates(), git); + } + // checkout after fetch so we can get any new branches, tags, ect. checkout(git, label); if (isBranch(git, label)) { // merge results from fetch @@ -201,7 +227,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository logger.warn( "The local repository is dirty. Resetting it to origin/" + label + "."); - resetHard(git, label, "refs/remotes/origin/" + label); + resetHard(git, label, LOCAL_BRANCH_REF_PREFIX + label); } } } @@ -258,6 +284,55 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository } + /** + * Deletes local branches if corresponding remote branch was removed. + * + * @param trackingRefUpdates list of tracking ref updates + * @param git git instance + * @return list of deleted branches + */ + private Collection deleteUntrackedLocalBranches(Collection trackingRefUpdates, Git git) { + if (CollectionUtils.isEmpty(trackingRefUpdates)) { + return Collections.emptyList(); + } + + Collection branchesToDelete = new ArrayList<>(); + for (TrackingRefUpdate trackingRefUpdate : trackingRefUpdates) { + ReceiveCommand receiveCommand = trackingRefUpdate.asReceiveCommand(); + if (receiveCommand.getType() == DELETE) { + String localRefName = trackingRefUpdate.getLocalName(); + if (StringUtils.startsWithIgnoreCase(localRefName, LOCAL_BRANCH_REF_PREFIX)) { + String localBranchName = localRefName.substring(LOCAL_BRANCH_REF_PREFIX.length(), localRefName.length()); + branchesToDelete.add(localBranchName); + } + } + } + + if (CollectionUtils.isEmpty(branchesToDelete)) { + return Collections.emptyList(); + } + + try { + //make sure that deleted branch not a current one + checkout(git, defaultLabel); + return deleteBranches(git, branchesToDelete); + } catch (Exception ex) { + String message = format("Failed to delete %s branches.", branchesToDelete); + warn(message, ex); + return Collections.emptyList(); + } + } + + private List deleteBranches(Git git, Collection branchesToDelete) throws GitAPIException { + DeleteBranchCommand deleteBranchCommand = git.branchDelete() + .setBranchNames(branchesToDelete.toArray(new String[0])) + //local branch can contain data which is not merged to HEAD - force delete it anyway, since local copy should be R/O + .setForce(true); + List resultList = deleteBranchCommand.call(); + logger.info(format("Deleted %s branches from %s branches to delete.", resultList, branchesToDelete)); + return resultList; + } + private Ref checkout(Git git, String label) throws GitAPIException { CheckoutCommand checkout = git.checkout(); if (shouldTrack(git, label)) { @@ -296,7 +371,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository Set dirties = dirties(status.getAdded(), status.getChanged(), status.getRemoved(), status.getMissing(), status.getModified(), status.getConflicting(), status.getUntracked()); - this.logger.warn(String.format("Dirty files found: %s", dirties)); + this.logger.warn(format("Dirty files found: %s", dirties)); } @SuppressWarnings("unchecked") @@ -316,6 +391,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository FetchCommand fetch = git.fetch(); fetch.setRemote("origin"); fetch.setTagOpt(TagOpt.FETCH_TAGS); + fetch.setRemoveDeletedRefs(deleteUntrackedBranches); configureCommand(fetch); try { diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitConfigServerTestData.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitConfigServerTestData.java index dc4c06fd..fe7c674d 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitConfigServerTestData.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitConfigServerTestData.java @@ -17,6 +17,7 @@ package org.springframework.cloud.config.server.environment; import org.eclipse.jgit.api.Git; + import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.config.server.test.ConfigServerTestUtils; import org.springframework.context.ConfigurableApplicationContext; @@ -24,6 +25,9 @@ import org.springframework.util.FileSystemUtils; import org.springframework.util.ResourceUtils; import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; /** * Class that holds objects that can be used for testing @@ -78,7 +82,13 @@ public class JGitConfigServerTestData { return this.context; } - public static JGitConfigServerTestData prepareClonedGitRepository(Object... sources) throws Exception { + public static JGitConfigServerTestData prepareClonedGitRepository(Object... sources) + throws Exception { + return prepareClonedGitRepositoryWithProps(Collections.emptySet(), sources); + } + + public static JGitConfigServerTestData prepareClonedGitRepositoryWithProps(Collection additionalProperties, Object... sources) + throws Exception { //setup remote repository String remoteUri = ConfigServerTestUtils.prepareLocalRepo(); File remoteRepoDir = ResourceUtils.getFile(remoteUri); @@ -100,8 +110,11 @@ public class JGitConfigServerTestData { .call(); //setup our test spring application pointing to the local repo + Collection properties = new ArrayList<>(additionalProperties); + properties.add("spring.cloud.config.server.git.uri:" + "file://" + clonedRepoDir.getAbsolutePath()); ConfigurableApplicationContext context = new SpringApplicationBuilder(sources).web(false) - .properties("spring.cloud.config.server.git.uri:" + "file://" + clonedRepoDir.getAbsolutePath()).run(); + .properties(properties.toArray(new String[0])) + .run(); JGitEnvironmentRepository repository = context.getBean(JGitEnvironmentRepository.class); return new JGitConfigServerTestData( diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryIntegrationTests.java index 1417c73b..6e23de52 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryIntegrationTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryIntegrationTests.java @@ -26,6 +26,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.util.Arrays; +import java.util.Collections; import org.eclipse.jgit.api.CheckoutCommand; import org.eclipse.jgit.api.Git; @@ -503,6 +504,42 @@ public class JGitEnvironmentRepositoryIntegrationTests { assertNotNull(repository.getTransportConfigCallback()); } + @Test + public void testShouldReturnEnvironmentFromLocalBranchInCaseRemoteDeleted() throws Exception { + JGitConfigServerTestData testData = JGitConfigServerTestData + .prepareClonedGitRepository(TestConfiguration.class); + + String branchToDelete = "branchToDelete"; + testData.getServerGit().getGit().branchCreate().setName(branchToDelete).call(); + + Environment environment = testData.getRepository().findOne("bar", "staging", "branchToDelete"); + assertNotNull(environment); + + testData.getServerGit().getGit().branchDelete().setBranchNames(branchToDelete).call(); + environment = testData.getRepository().findOne("bar", "staging", "branchToDelete"); + assertNotNull(environment); + } + + @Test(expected = NoSuchLabelException.class) + public void testShouldFailIfRemoteBranchWasDeleted() throws Exception { + JGitConfigServerTestData testData = JGitConfigServerTestData + .prepareClonedGitRepositoryWithProps(Collections.singleton("spring.cloud.config.server.git.deleteUntrackedBranches=true"), + TestConfiguration.class); + + String branchToDelete = "branchToDelete"; + testData.getServerGit().getGit().branchCreate().setName(branchToDelete).call(); + + //checkout and simulate regular flow + Environment environment = testData.getRepository().findOne("bar", "staging", "branchToDelete"); + assertNotNull(environment); + + //remove branch + testData.getServerGit().getGit().branchDelete().setBranchNames(branchToDelete).call(); + + //test + testData.getRepository().findOne("bar", "staging", "branchToDelete"); + } + @Configuration @EnableConfigurationProperties(ConfigServerProperties.class) @Import({ PropertyPlaceholderAutoConfiguration.class, EnvironmentRepositoryConfiguration.class }) diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java index 9d87cf99..2e6caf7d 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java @@ -19,16 +19,19 @@ package org.springframework.cloud.config.server.environment; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; import org.apache.commons.logging.Log; import org.eclipse.jgit.api.CheckoutCommand; import org.eclipse.jgit.api.CloneCommand; +import org.eclipse.jgit.api.DeleteBranchCommand; import org.eclipse.jgit.api.FetchCommand; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.ListBranchCommand; import org.eclipse.jgit.api.MergeCommand; +import org.eclipse.jgit.api.MergeResult; import org.eclipse.jgit.api.ResetCommand; import org.eclipse.jgit.api.Status; import org.eclipse.jgit.api.StatusCommand; @@ -44,6 +47,7 @@ import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.transport.CredentialItem; import org.eclipse.jgit.transport.CredentialsProvider; import org.eclipse.jgit.transport.FetchResult; +import org.eclipse.jgit.transport.ReceiveCommand; import org.eclipse.jgit.transport.TrackingRefUpdate; import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; @@ -82,7 +86,7 @@ import static org.mockito.Mockito.when; public class JGitEnvironmentRepositoryTests { private StandardEnvironment environment = new StandardEnvironment(); - private JGitEnvironmentRepository repository = new JGitEnvironmentRepository(this.environment); + private JGitEnvironmentRepository repository; private File basedir = new File("target/config"); @@ -92,6 +96,7 @@ public class JGitEnvironmentRepositoryTests { @Before public void init() throws Exception { String uri = ConfigServerTestUtils.prepareLocalRepo(); + this.repository = new JGitEnvironmentRepository(this.environment); this.repository.setUri(uri); if (this.basedir.exists()) { FileUtils.delete(this.basedir, FileUtils.RECURSIVE | FileUtils.RETRY); @@ -385,6 +390,8 @@ public class JGitEnvironmentRepositoryTests { SearchPathLocator.Locations locations = this.repository.getLocations("bar", "staging", null); assertEquals(locations.getVersion(), newObjectId.getName()); + + verify(git, times(0)).branchDelete(); } @Test @@ -441,6 +448,8 @@ public class JGitEnvironmentRepositoryTests { SearchPathLocator.Locations locations = this.repository.getLocations("bar", "staging", "master"); assertEquals(locations.getVersion(),newObjectId.getName()); + + verify(git, times(0)).branchDelete(); } @Test @@ -509,6 +518,8 @@ public class JGitEnvironmentRepositoryTests { SearchPathLocator.Locations locations = this.repository.getLocations("bar", "staging", "master"); assertEquals(locations.getVersion(), newObjectId.getName()); + + verify(git, times(0)).branchDelete(); } @Test @@ -716,6 +727,110 @@ public class JGitEnvironmentRepositoryTests { verify(fetchCommand, times(1)).setTransportConfigCallback(configCallback); } + @Test + public void shouldSetRemoveBranchesFlagToFetchCommand() throws Exception { + Git mockGit = mock(Git.class); + FetchCommand fetchCommand = mock(FetchCommand.class); + + when(mockGit.fetch()).thenReturn(fetchCommand); + when(fetchCommand.call()).thenReturn(mock(FetchResult.class)); + + repository.setGitFactory(new MockGitFactory(mockGit, mock(CloneCommand.class))); + repository.setUri("http://somegitserver/somegitrepo"); + repository.setDeleteUntrackedBranches(true); + + repository.fetch(mockGit, "master"); + + verify(fetchCommand, times(1)).setRemoveDeletedRefs(true); + verify(fetchCommand, times(1)).call(); + } + + @Test + public void shouldHandleExceptionWhileRemovingBranches() throws Exception { + Git git = mock(Git.class); + CloneCommand cloneCommand = mock(CloneCommand.class); + MockGitFactory factory = new MockGitFactory(git, cloneCommand); + this.repository.setGitFactory(factory); + this.repository.setDeleteUntrackedBranches(true); + + // refresh()->shouldPull + StatusCommand statusCommand = mock(StatusCommand.class); + Status status = mock(Status.class); + when(git.status()).thenReturn(statusCommand); + Repository repository = mock(Repository.class); + when(git.getRepository()).thenReturn(repository); + StoredConfig storedConfig = mock(StoredConfig.class); + when(repository.getConfig()).thenReturn(storedConfig); + when(storedConfig.getString("remote", "origin", "url")).thenReturn("http://example/git"); + when(statusCommand.call()).thenReturn(status); + when(status.isClean()).thenReturn(true); + + // refresh()->fetch + FetchCommand fetchCommand = mock(FetchCommand.class); + FetchResult fetchResult = mock(FetchResult.class); + + TrackingRefUpdate trackingRefUpdate = mock(TrackingRefUpdate.class); + Collection trackingRefUpdates = Collections.singletonList(trackingRefUpdate); + + when(git.fetch()).thenReturn(fetchCommand); + when(fetchCommand.setRemote(anyString())).thenReturn(fetchCommand); + when(fetchCommand.call()).thenReturn(fetchResult); + when(fetchResult.getTrackingRefUpdates()).thenReturn(trackingRefUpdates); + + // refresh()->deleteBranch + ReceiveCommand receiveCommand = mock(ReceiveCommand.class); + when(trackingRefUpdate.asReceiveCommand()).thenReturn(receiveCommand); + when(receiveCommand.getType()).thenReturn(ReceiveCommand.Type.DELETE); + when(trackingRefUpdate.getLocalName()).thenReturn("refs/remotes/origin/feature/deletedBranchFromOrigin"); + + DeleteBranchCommand deleteBranchCommand = mock(DeleteBranchCommand.class); + when(git.branchDelete()).thenReturn(deleteBranchCommand); + when(deleteBranchCommand.setBranchNames(eq("feature/deletedBranchFromOrigin"))).thenReturn(deleteBranchCommand); + when(deleteBranchCommand.setForce(true)).thenReturn(deleteBranchCommand); + when(deleteBranchCommand.call()).thenThrow(new NotMergedException());// here + // is + // our + // exception + // we + // are + // testing + + // refresh()->checkout + CheckoutCommand checkoutCommand = mock(CheckoutCommand.class); + // refresh()->checkout->containsBranch + ListBranchCommand listBranchCommand = mock(ListBranchCommand.class); + when(git.checkout()).thenReturn(checkoutCommand); + when(git.branchList()).thenReturn(listBranchCommand); + List refs = new ArrayList<>(); + Ref ref = mock(Ref.class); + refs.add(ref); + when(ref.getName()).thenReturn("/master"); + when(listBranchCommand.call()).thenReturn(refs); + + // refresh()->merge + MergeResult mergeResult = mock(MergeResult.class); + MergeResult.MergeStatus mergeStatus = mock(MergeResult.MergeStatus.class); + MergeCommand mergeCommand = mock(MergeCommand.class); + when(git.merge()).thenReturn(mergeCommand); + when(mergeCommand.call()).thenReturn(mergeResult); + when(mergeResult.getMergeStatus()).thenReturn(mergeStatus); + when(mergeStatus.isSuccessful()).thenReturn(true); + + // refresh()->return + Ref headRef = mock(Ref.class); + when(repository.getRef(anyString())).thenReturn(headRef); + + ObjectId newObjectId = ObjectId.fromRaw(new int[]{1, 2, 3, 4, 5}); + when(headRef.getObjectId()).thenReturn(newObjectId); + + SearchPathLocator.Locations locations = this.repository.getLocations("bar", "staging", "master"); + assertEquals(locations.getVersion(), newObjectId.getName()); + + verify(deleteBranchCommand).setBranchNames(eq("feature/deletedBranchFromOrigin")); + verify(deleteBranchCommand).setForce(true); + verify(deleteBranchCommand).call(); + } + class MockCloneCommand extends CloneCommand { private Git mockGit; From a90c254d2a025d1af50fd6638f593d7e80d24f99 Mon Sep 17 00:00:00 2001 From: Ryan Baxter Date: Mon, 26 Mar 2018 12:15:27 -0400 Subject: [PATCH 3/8] Using latest build snapshot for commons --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0d4a609a..8f0f9724 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ config - 1.3.0.RELEASE + 1.3.3.BUILD-SNAPSHOT spring-cloud-config-dependencies From 941672d5c7478ea52d3a2b27fff5c25cc61d9a65 Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Thu, 22 Mar 2018 14:40:48 -0400 Subject: [PATCH 4/8] Use new RSA properties --- .../server/config/EncryptionAutoConfiguration.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/EncryptionAutoConfiguration.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/EncryptionAutoConfiguration.java index 8636dada..658322be 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/EncryptionAutoConfiguration.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/config/EncryptionAutoConfiguration.java @@ -24,6 +24,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.bootstrap.encrypt.KeyProperties; import org.springframework.cloud.bootstrap.encrypt.KeyProperties.KeyStore; +import org.springframework.cloud.bootstrap.encrypt.RsaProperties; import org.springframework.cloud.config.server.encryption.CipherEnvironmentEncryptor; import org.springframework.cloud.config.server.encryption.EnvironmentEncryptor; import org.springframework.cloud.config.server.encryption.KeyStoreTextEncryptorLocator; @@ -37,6 +38,7 @@ import org.springframework.context.annotation.Import; import org.springframework.security.crypto.encrypt.Encryptors; import org.springframework.security.crypto.encrypt.TextEncryptor; import org.springframework.security.rsa.crypto.KeyStoreKeyFactory; +import org.springframework.security.rsa.crypto.RsaAlgorithm; import org.springframework.security.rsa.crypto.RsaSecretEncryptor; import org.springframework.util.StringUtils; @@ -85,6 +87,9 @@ public class EncryptionAutoConfiguration { @Autowired private KeyProperties key; + @Autowired + private RsaProperties rsaProperties; + @Bean @ConditionalOnMissingBean public TextEncryptorLocator textEncryptorLocator() { @@ -92,9 +97,10 @@ public class EncryptionAutoConfiguration { KeyStoreTextEncryptorLocator locator = new KeyStoreTextEncryptorLocator( new KeyStoreKeyFactory(keyStore.getLocation(), keyStore.getPassword().toCharArray()), keyStore.getSecret(), keyStore.getAlias()); - locator.setRsaAlgorithm(this.key.getRsa().getAlgorithm()); - locator.setSalt(this.key.getRsa().getSalt()); - locator.setStrong(this.key.getRsa().isStrong()); + RsaAlgorithm algorithm = this.rsaProperties.getAlgorithm(); + locator.setRsaAlgorithm(algorithm); + locator.setSalt(this.rsaProperties.getSalt()); + locator.setStrong(this.rsaProperties.isStrong()); return locator; } From f9a6a884910f3666d0cd301f230b715ec6e5b524 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Mon, 26 Mar 2018 16:24:35 +0000 Subject: [PATCH 5/8] Update SNAPSHOT to 1.4.3.RELEASE --- docs/pom.xml | 2 +- pom.xml | 4 ++-- spring-cloud-config-client/pom.xml | 2 +- spring-cloud-config-dependencies/pom.xml | 4 ++-- spring-cloud-config-monitor/pom.xml | 4 ++-- spring-cloud-config-sample/pom.xml | 2 +- spring-cloud-config-server/pom.xml | 2 +- spring-cloud-starter-config/pom.xml | 4 ++-- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 39c6255e..6bfcf650 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-config - 1.4.3.BUILD-SNAPSHOT + 1.4.3.RELEASE .. diff --git a/pom.xml b/pom.xml index 8f0f9724..8ff3368a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.springframework.cloud spring-cloud-config - 1.4.3.BUILD-SNAPSHOT + 1.4.3.RELEASE pom Spring Cloud Config Spring Cloud Config @@ -22,7 +22,7 @@ config - 1.3.3.BUILD-SNAPSHOT + 1.3.3.RELEASE spring-cloud-config-dependencies diff --git a/spring-cloud-config-client/pom.xml b/spring-cloud-config-client/pom.xml index 346cf905..611e742c 100644 --- a/spring-cloud-config-client/pom.xml +++ b/spring-cloud-config-client/pom.xml @@ -10,7 +10,7 @@ org.springframework.cloud spring-cloud-config - 1.4.3.BUILD-SNAPSHOT + 1.4.3.RELEASE .. diff --git a/spring-cloud-config-dependencies/pom.xml b/spring-cloud-config-dependencies/pom.xml index 44245d9e..b26e5c9e 100644 --- a/spring-cloud-config-dependencies/pom.xml +++ b/spring-cloud-config-dependencies/pom.xml @@ -5,11 +5,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 1.3.8.BUILD-SNAPSHOT + 1.3.8.RELEASE spring-cloud-config-dependencies - 1.4.3.BUILD-SNAPSHOT + 1.4.3.RELEASE pom spring-cloud-config-dependencies Spring Cloud Config Dependencies diff --git a/spring-cloud-config-monitor/pom.xml b/spring-cloud-config-monitor/pom.xml index 63a2cecc..49da64a4 100644 --- a/spring-cloud-config-monitor/pom.xml +++ b/spring-cloud-config-monitor/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-config - 1.4.3.BUILD-SNAPSHOT + 1.4.3.RELEASE .. spring-cloud-config-monitor @@ -13,7 +13,7 @@ Spring Cloud Config Monitor ${basedir}/../.. - 1.3.2.RELEASE + 1.3.3.RELEASE diff --git a/spring-cloud-config-sample/pom.xml b/spring-cloud-config-sample/pom.xml index a78861cb..ab67ce8b 100644 --- a/spring-cloud-config-sample/pom.xml +++ b/spring-cloud-config-sample/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-config - 1.4.3.BUILD-SNAPSHOT + 1.4.3.RELEASE .. diff --git a/spring-cloud-config-server/pom.xml b/spring-cloud-config-server/pom.xml index d11fa08f..de27c17f 100644 --- a/spring-cloud-config-server/pom.xml +++ b/spring-cloud-config-server/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-config - 1.4.3.BUILD-SNAPSHOT + 1.4.3.RELEASE .. diff --git a/spring-cloud-starter-config/pom.xml b/spring-cloud-starter-config/pom.xml index 03efa57a..48da9ae5 100644 --- a/spring-cloud-starter-config/pom.xml +++ b/spring-cloud-starter-config/pom.xml @@ -5,10 +5,10 @@ org.springframework.cloud spring-cloud-config - 1.4.3.BUILD-SNAPSHOT + 1.4.3.RELEASE spring-cloud-starter-config - 1.4.3.BUILD-SNAPSHOT + 1.4.3.RELEASE spring-cloud-starter-config Spring Cloud Starter https://projects.spring.io/spring-cloud From 739f4c1ca8637789f1bd8a4910e947d82da8acb0 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Mon, 26 Mar 2018 16:26:00 +0000 Subject: [PATCH 6/8] Going back to snapshots --- docs/pom.xml | 2 +- pom.xml | 4 ++-- spring-cloud-config-client/pom.xml | 2 +- spring-cloud-config-dependencies/pom.xml | 4 ++-- spring-cloud-config-monitor/pom.xml | 4 ++-- spring-cloud-config-sample/pom.xml | 2 +- spring-cloud-config-server/pom.xml | 2 +- spring-cloud-starter-config/pom.xml | 4 ++-- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 6bfcf650..39c6255e 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-config - 1.4.3.RELEASE + 1.4.3.BUILD-SNAPSHOT .. diff --git a/pom.xml b/pom.xml index 8ff3368a..8f0f9724 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.springframework.cloud spring-cloud-config - 1.4.3.RELEASE + 1.4.3.BUILD-SNAPSHOT pom Spring Cloud Config Spring Cloud Config @@ -22,7 +22,7 @@ config - 1.3.3.RELEASE + 1.3.3.BUILD-SNAPSHOT spring-cloud-config-dependencies diff --git a/spring-cloud-config-client/pom.xml b/spring-cloud-config-client/pom.xml index 611e742c..346cf905 100644 --- a/spring-cloud-config-client/pom.xml +++ b/spring-cloud-config-client/pom.xml @@ -10,7 +10,7 @@ org.springframework.cloud spring-cloud-config - 1.4.3.RELEASE + 1.4.3.BUILD-SNAPSHOT .. diff --git a/spring-cloud-config-dependencies/pom.xml b/spring-cloud-config-dependencies/pom.xml index b26e5c9e..44245d9e 100644 --- a/spring-cloud-config-dependencies/pom.xml +++ b/spring-cloud-config-dependencies/pom.xml @@ -5,11 +5,11 @@ spring-cloud-dependencies-parent org.springframework.cloud - 1.3.8.RELEASE + 1.3.8.BUILD-SNAPSHOT spring-cloud-config-dependencies - 1.4.3.RELEASE + 1.4.3.BUILD-SNAPSHOT pom spring-cloud-config-dependencies Spring Cloud Config Dependencies diff --git a/spring-cloud-config-monitor/pom.xml b/spring-cloud-config-monitor/pom.xml index 49da64a4..63a2cecc 100644 --- a/spring-cloud-config-monitor/pom.xml +++ b/spring-cloud-config-monitor/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-config - 1.4.3.RELEASE + 1.4.3.BUILD-SNAPSHOT .. spring-cloud-config-monitor @@ -13,7 +13,7 @@ Spring Cloud Config Monitor ${basedir}/../.. - 1.3.3.RELEASE + 1.3.2.RELEASE diff --git a/spring-cloud-config-sample/pom.xml b/spring-cloud-config-sample/pom.xml index ab67ce8b..a78861cb 100644 --- a/spring-cloud-config-sample/pom.xml +++ b/spring-cloud-config-sample/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-config - 1.4.3.RELEASE + 1.4.3.BUILD-SNAPSHOT .. diff --git a/spring-cloud-config-server/pom.xml b/spring-cloud-config-server/pom.xml index de27c17f..d11fa08f 100644 --- a/spring-cloud-config-server/pom.xml +++ b/spring-cloud-config-server/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-config - 1.4.3.RELEASE + 1.4.3.BUILD-SNAPSHOT .. diff --git a/spring-cloud-starter-config/pom.xml b/spring-cloud-starter-config/pom.xml index 48da9ae5..03efa57a 100644 --- a/spring-cloud-starter-config/pom.xml +++ b/spring-cloud-starter-config/pom.xml @@ -5,10 +5,10 @@ org.springframework.cloud spring-cloud-config - 1.4.3.RELEASE + 1.4.3.BUILD-SNAPSHOT spring-cloud-starter-config - 1.4.3.RELEASE + 1.4.3.BUILD-SNAPSHOT spring-cloud-starter-config Spring Cloud Starter https://projects.spring.io/spring-cloud From 6402ec099db69c227923b77ab3848e7aef4d75bb Mon Sep 17 00:00:00 2001 From: buildmaster Date: Mon, 26 Mar 2018 16:26:01 +0000 Subject: [PATCH 7/8] Bumping versions to 1.4.4.BUILD-SNAPSHOT after release --- docs/pom.xml | 2 +- pom.xml | 2 +- spring-cloud-config-client/pom.xml | 2 +- spring-cloud-config-dependencies/pom.xml | 2 +- spring-cloud-config-monitor/pom.xml | 2 +- spring-cloud-config-sample/pom.xml | 2 +- spring-cloud-config-server/pom.xml | 2 +- spring-cloud-starter-config/pom.xml | 4 ++-- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 39c6255e..43b15ebf 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-config - 1.4.3.BUILD-SNAPSHOT + 1.4.4.BUILD-SNAPSHOT .. diff --git a/pom.xml b/pom.xml index 8f0f9724..8a78e133 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.springframework.cloud spring-cloud-config - 1.4.3.BUILD-SNAPSHOT + 1.4.4.BUILD-SNAPSHOT pom Spring Cloud Config Spring Cloud Config diff --git a/spring-cloud-config-client/pom.xml b/spring-cloud-config-client/pom.xml index 346cf905..49f314e9 100644 --- a/spring-cloud-config-client/pom.xml +++ b/spring-cloud-config-client/pom.xml @@ -10,7 +10,7 @@ org.springframework.cloud spring-cloud-config - 1.4.3.BUILD-SNAPSHOT + 1.4.4.BUILD-SNAPSHOT .. diff --git a/spring-cloud-config-dependencies/pom.xml b/spring-cloud-config-dependencies/pom.xml index 44245d9e..139f7d69 100644 --- a/spring-cloud-config-dependencies/pom.xml +++ b/spring-cloud-config-dependencies/pom.xml @@ -9,7 +9,7 @@ spring-cloud-config-dependencies - 1.4.3.BUILD-SNAPSHOT + 1.4.4.BUILD-SNAPSHOT pom spring-cloud-config-dependencies Spring Cloud Config Dependencies diff --git a/spring-cloud-config-monitor/pom.xml b/spring-cloud-config-monitor/pom.xml index 63a2cecc..9d856913 100644 --- a/spring-cloud-config-monitor/pom.xml +++ b/spring-cloud-config-monitor/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-config - 1.4.3.BUILD-SNAPSHOT + 1.4.4.BUILD-SNAPSHOT .. spring-cloud-config-monitor diff --git a/spring-cloud-config-sample/pom.xml b/spring-cloud-config-sample/pom.xml index a78861cb..a8b4d6c6 100644 --- a/spring-cloud-config-sample/pom.xml +++ b/spring-cloud-config-sample/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-config - 1.4.3.BUILD-SNAPSHOT + 1.4.4.BUILD-SNAPSHOT .. diff --git a/spring-cloud-config-server/pom.xml b/spring-cloud-config-server/pom.xml index d11fa08f..7f6254b2 100644 --- a/spring-cloud-config-server/pom.xml +++ b/spring-cloud-config-server/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-config - 1.4.3.BUILD-SNAPSHOT + 1.4.4.BUILD-SNAPSHOT .. diff --git a/spring-cloud-starter-config/pom.xml b/spring-cloud-starter-config/pom.xml index 03efa57a..f21b4369 100644 --- a/spring-cloud-starter-config/pom.xml +++ b/spring-cloud-starter-config/pom.xml @@ -5,10 +5,10 @@ org.springframework.cloud spring-cloud-config - 1.4.3.BUILD-SNAPSHOT + 1.4.4.BUILD-SNAPSHOT spring-cloud-starter-config - 1.4.3.BUILD-SNAPSHOT + 1.4.4.BUILD-SNAPSHOT spring-cloud-starter-config Spring Cloud Starter https://projects.spring.io/spring-cloud From 62e6871711303e56f5ac112153a58a291790dee8 Mon Sep 17 00:00:00 2001 From: Taras Danylchuk Date: Thu, 29 Mar 2018 23:27:44 +0300 Subject: [PATCH 8/8] Fix delete untracked branch feature if fetch result is null / git repo unavailable (#955) --- .../config/server/environment/JGitEnvironmentRepository.java | 4 ++-- .../server/environment/JGitEnvironmentRepositoryTests.java | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java index 6db6dbda..1fd7ed7e 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepository.java @@ -215,7 +215,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository git = createGitClient(); if (shouldPull(git)) { FetchResult fetchStatus = fetch(git, label); - if(deleteUntrackedBranches) { + if (deleteUntrackedBranches && fetchStatus != null) { deleteUntrackedLocalBranches(fetchStatus.getTrackingRefUpdates(), git); } // checkout after fetch so we can get any new branches, tags, ect. @@ -265,7 +265,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository /** * Clones the remote repository and then opens a connection to it. - * + * * @throws GitAPIException * @throws IOException */ diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java index 2e6caf7d..23c555aa 100644 --- a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/environment/JGitEnvironmentRepositoryTests.java @@ -332,6 +332,7 @@ public class JGitEnvironmentRepositoryTests { CloneCommand cloneCommand = mock(CloneCommand.class); MockGitFactory factory = new MockGitFactory(git, cloneCommand); this.repository.setGitFactory(factory); + this.repository.setDeleteUntrackedBranches(true); // refresh()->shouldPull StatusCommand statusCommand = mock(StatusCommand.class);