Skip to content

Commit c7c45b3

Browse files
committed
Fix transport version tests on windows (elastic#134739)
Running on windows has some slightly different behavior when interacting with the filesystem. In particular, this commit fixes the changed resources prefix when looking at changed resources in git to always use forward slashes as git outputs them. It also fixes the case that CI uses a non-main (eg master) branch as the default branch. Finally it fixes git diff so it outputs paths relative to the transport resources dir, as ls-files does.
1 parent 1ab1176 commit c7c45b3

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/transport/AbstractTransportVersionFuncTest.groovy

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ class AbstractTransportVersionFuncTest extends AbstractGradleFuncTest {
155155
"""
156156

157157
setupLocalGitRepo()
158-
execute("git checkout -b main")
158+
String currentBranch = execute("git branch --show-current")
159+
if (currentBranch.strip().equals("main") == false) {
160+
// make sure a main branch exists, some CI doesn't have main set as the default branch
161+
execute("git checkout -b main")
162+
}
159163
execute("git checkout -b test")
160164
}
161165

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/transport/TransportVersionResourcesService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ TransportVersionDefinition getReferableDefinitionFromUpstream(String name) {
122122
/** Get the definition names which have local changes relative to upstream */
123123
List<String> getChangedReferableDefinitionNames() {
124124
List<String> changedDefinitions = new ArrayList<>();
125-
String referablePrefix = REFERABLE_DIR.toString();
125+
// make sure the prefix is git style paths, always forward slashes
126+
String referablePrefix = REFERABLE_DIR.toString().replace('\\', '/');
126127
for (String changedPath : getChangedResources()) {
127128
if (changedPath.contains(referablePrefix) == false) {
128129
continue;
@@ -304,7 +305,7 @@ private Set<String> getChangedResources() {
304305
synchronized (changedResources) {
305306
HashSet<String> resources = new HashSet<>();
306307

307-
String diffOutput = gitCommand("diff", "--name-only", getUpstreamRefName(), ".");
308+
String diffOutput = gitCommand("diff", "--name-only", "--relative", getUpstreamRefName(), ".");
308309
if (diffOutput.strip().isEmpty() == false) {
309310
Collections.addAll(resources, diffOutput.split("\n")); // git always outputs LF
310311
}

0 commit comments

Comments
 (0)