fix(git): match the clone directory for a URL ending in .git/
What does this MR do and why?
When a clone URL ends in .git/, RunClone returns the wrong directory:
target = path.Base(strings.TrimSuffix(cloneURL, ".git"))strings.TrimSuffix("....git/", ".git") does not match, because the suffix is
.git/ rather than .git, so the result keeps it:
https://gitlab.com/group/source.git -> "source" correct
https://gitlab.com/group/source.git/ -> "source.git" git clones into "source"
https://gitlab.com/group/source/ -> "source" correct
git@gitlab.com:group/source.git -> "source" correctOnly the .git/ form is affected, and there the returned path points at a
directory that does not exist, which breaks any caller that uses it.
Trailing slashes are now trimmed before the suffix is stripped. The logic is
extracted into cloneTargetDir so it can be tested without running git.
Test coverage
Test_cloneTargetDir covers .git, no suffix, trailing slash, .git/ and
scp-style forms, all expecting source. The .git/ case is the one that fails
on the current logic.
One thing to flag for the reviewer: go test ./internal/git/ is not clean on
Windows, but it is not clean on main either. Test_AddStackBaseBranch,
Test_StackBaseBranch, Test_StackRemoveBranch and Test_StackRootDir all
fail there before this change, from an unrelated leaked file handle in
AddStackBaseBranch (that is !3569 (merged)). This MR does not touch any of them, and
go test ./internal/git/ -run Test_cloneTargetDir passes.
Related issues
Closes #8437 (closed)