spacelift-io / spacectl

Spacelift client and CLI
MIT License
131 stars 35 forks source link

Use filepath functions for path manipulation in getGitRepositorySubdir #177

Closed JeffreyVdb closed 1 year ago

JeffreyVdb commented 1 year ago

Before this commit, the root directory would be removed which leaves a trailing file separator character in the beginning. This would then be trimmed by using strings.TrimPrefix. The problem here is that it uses a hardcoded file separator character which won't work on Windows because Windows uses a backslash instead of a forward slash.

Using filepath.Rel to get the directory relative to the root directory will not leave a separator character in the beginning.

It's also important to use filepath.ToSlash which will translate every file separator character to the forward slash.

This commit makes discovery work on Windows which it didn't before.

JeffreyVdb commented 1 year ago

Just for clearness. On windows, the return value of this function for a subdirectory called "foobar\something' would be:

\foobar\something

instead of

foobar/something
tomasmik commented 1 year ago

Hey, thanks for your contribution. Please allow for some time to test this as this is Windows specific.

JeffreyVdb commented 1 year ago

The last commit should also be applicable to Linux. It should endlessly loop on all platforms (before this fix).

tomasmik commented 1 year ago

Tested and merged, thanks @JeffreyVdb