diff --git a/docs/modules/ROOT/pages/server/environment-repository/git-backend.adoc b/docs/modules/ROOT/pages/server/environment-repository/git-backend.adoc index dd95eb0350..92dfe9b853 100644 --- a/docs/modules/ROOT/pages/server/environment-repository/git-backend.adoc +++ b/docs/modules/ROOT/pages/server/environment-repository/git-backend.adoc @@ -443,7 +443,7 @@ You can control how often the config server will fetch updated configuration dat from your Git backend by using `spring.cloud.config.server.git.refreshRate`. The value of this property is specified in seconds. By default the value is 0, meaning the config server will fetch updated configuration from the Git repo every time it -is requested. +is requested. If the value is a negative number the refresh will not occur. [[default-label]] == Default Label 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 bfe6ef304b..c4434ab07c 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 @@ -470,7 +470,7 @@ private Ref checkout(Git git, String label) throws GitAPIException { protected boolean shouldPull(Git git) throws GitAPIException { boolean shouldPull; - if (this.refreshRate > 0 && System.currentTimeMillis() - this.lastRefresh < (this.refreshRate * 1000)) { + if (this.refreshRate < 0 || (this.refreshRate > 0 && System.currentTimeMillis() - this.lastRefresh < (this.refreshRate * 1000))) { return false; } 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 b6422d7442..6239189db9 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 @@ -523,6 +523,32 @@ public void shouldNotRefresh() throws Exception { assertThat(shouldPull).as("shouldPull was true").isFalse(); } + @Test + public void shouldNotRefreshWhenNegativeValue() throws Exception { + Git git = mock(Git.class); + StatusCommand statusCommand = mock(StatusCommand.class); + Status status = mock(Status.class); + Repository repository = mock(Repository.class); + StoredConfig storedConfig = mock(StoredConfig.class); + + when(git.status()).thenReturn(statusCommand); + when(git.getRepository()).thenReturn(repository); + 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); + + JGitEnvironmentProperties properties = new JGitEnvironmentProperties(); + properties.setRefreshRate(-1); + + JGitEnvironmentRepository repo = new JGitEnvironmentRepository(this.environment, properties, + ObservationRegistry.NOOP); + + boolean shouldPull = repo.shouldPull(git); + + assertThat(shouldPull).as("shouldPull was true").isFalse(); + } + @Test public void shouldUpdateLastRefresh() throws Exception { Git git = mock(Git.class);