Exact match of branch names in JGitEnvironmentRepository - Fixes gh-2133 (#2147)

This commit is contained in:
woshikid
2022-09-21 22:39:10 +08:00
committed by GitHub
parent a0b76c1c96
commit 5e162cb8f1
23 changed files with 40 additions and 5 deletions

View File

@@ -721,7 +721,7 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
}
List<Ref> branches = command.call();
for (Ref ref : branches) {
if (ref.getName().endsWith("/" + label)) {
if (ref.getName().equals("refs/heads/" + label) || ref.getName().equals("refs/remotes/origin/" + label)) {
return true;
}
}

View File

@@ -228,6 +228,20 @@ public class JGitEnvironmentRepositoryTests {
assertThat(this.repository.getUri()).isEqualTo("git://localhost/foo");
}
@Test
public void testBranchEndsWithTag() throws IOException {
String uri = ConfigServerTestUtils.prepareLocalRepo("branch-with-slash-repo");
this.repository.setUri(uri);
// exists branch "feature/foo"
Environment environment = this.repository.findOne("bar", "staging", "feature/foo");
assertVersion(environment);
// try tag "foo"
environment = this.repository.findOne("bar", "staging", "foo");
assertThat(environment.getPropertySources().get(0).getSource().get("key")).isEqualTo("value from tag");
}
@Test
public void afterPropertiesSet_CloneOnStartTrue_CloneAndFetchCalled() throws Exception {
Git mockGit = mock(Git.class);
@@ -740,7 +754,7 @@ public class JGitEnvironmentRepositoryTests {
when(checkoutCommand.call()).thenReturn(ref);
when(listBranchCommand.call()).thenReturn(Arrays.asList(branch1Ref));
when(fetchCommand.call()).thenReturn(fetchResult);
when(branch1Ref.getName()).thenReturn("origin/master");
when(branch1Ref.getName()).thenReturn("refs/remotes/origin/master");
when(status.isClean()).thenReturn(true);
JGitEnvironmentRepository repo = new JGitEnvironmentRepository(this.environment,
@@ -1203,12 +1217,12 @@ public class JGitEnvironmentRepositoryTests {
// Mock master branch
Ref mockMasterRef = mock(Ref.class);
repositoryRefsList.add(mockMasterRef);
when(mockMasterRef.getName()).thenReturn("/master");
when(mockMasterRef.getName()).thenReturn("refs/remotes/origin/master");
// Mock release branch.
Ref mockReleaseRef = mock(Ref.class);
repositoryRefsList.add(mockReleaseRef);
when(mockReleaseRef.getName()).thenReturn("/release");
when(mockReleaseRef.getName()).thenReturn("refs/remotes/origin/release");
// Mock calls on list and checkout commands
when(mockListBranchCommand.call()).thenReturn(repositoryRefsList);
@@ -1257,7 +1271,7 @@ public class JGitEnvironmentRepositoryTests {
// Mock master branch
Ref mockMasterRef = mock(Ref.class);
repositoryRefsList.add(mockMasterRef);
when(mockMasterRef.getName()).thenReturn("/master");
when(mockMasterRef.getName()).thenReturn("refs/remotes/origin/master");
// Mock calls on list and checkout commands
when(mockListBranchCommand.call()).thenReturn(repositoryRefsList);

View File

@@ -0,0 +1 @@
key: value from master

View File

@@ -0,0 +1 @@
ref: refs/heads/master

View File

@@ -0,0 +1,5 @@
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true

View File

@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.

View File

@@ -0,0 +1,3 @@
0000000000000000000000000000000000000000 7a9804f8901709bdcf794c553805d5bc5188f821 woshikid <name.kid@gmail.com> 1663579538 +0800 commit (initial): tag
7a9804f8901709bdcf794c553805d5bc5188f821 915bd24aaf815120f2755ef4fc66404f5d37b383 woshikid <name.kid@gmail.com> 1663579645 +0800 commit: branch
915bd24aaf815120f2755ef4fc66404f5d37b383 08eb9e67a7225c302e3906a63cb9544e619fc804 woshikid <name.kid@gmail.com> 1663579718 +0800 commit: master

View File

@@ -0,0 +1 @@
0000000000000000000000000000000000000000 915bd24aaf815120f2755ef4fc66404f5d37b383 woshikid <name.kid@gmail.com> 1663579678 +0800 branch: Created from master

View File

@@ -0,0 +1,3 @@
0000000000000000000000000000000000000000 7a9804f8901709bdcf794c553805d5bc5188f821 woshikid <name.kid@gmail.com> 1663579538 +0800 commit (initial): tag
7a9804f8901709bdcf794c553805d5bc5188f821 915bd24aaf815120f2755ef4fc66404f5d37b383 woshikid <name.kid@gmail.com> 1663579645 +0800 commit: branch
915bd24aaf815120f2755ef4fc66404f5d37b383 08eb9e67a7225c302e3906a63cb9544e619fc804 woshikid <name.kid@gmail.com> 1663579718 +0800 commit: master

View File

@@ -0,0 +1,2 @@
x<01><>A
<EFBFBD>0E]<5D><14>J<><4A>LR(<28>U&ql<71><6C>@<40>x}sw<><07><><EFBFBD>j-fv<66>~<7E><>]2SB<53><1C>G<EFBFBD>.EVL.<2E>l<13>L<16>$<18><><EFBFBD><1D>m<EFBFBD><6D><<3C>

View File

@@ -0,0 +1 @@
915bd24aaf815120f2755ef4fc66404f5d37b383

View File

@@ -0,0 +1 @@
08eb9e67a7225c302e3906a63cb9544e619fc804

View File

@@ -0,0 +1 @@
7a9804f8901709bdcf794c553805d5bc5188f821