Skip to content
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

fix: allow negative value for jgit environment to disable refresh #2393

Merged
merged 1 commit into from
Mar 18, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading