mirror of
https://github.com/x-motemen/ghq.git
synced 2026-09-10 07:26:27 -04:00
Remove trailing slash before stripping .git from the end
Fixed a problem that ghq get -u may clone to another directory 1. ghq get https://git.kernel.org/pub/scm/git/git.git/ -> GHQ_ROOT/git.kernel.org/pub/scm/git/git.git 2. ghq list | ghq get -u -> GHQ_ROOT/git.kernel.org/pub/scm/git/git
This commit is contained in:
parent
f0bdf0c4bd
commit
0b8805b2f0
|
|
@ -122,8 +122,8 @@ func (g *getter) getRemoteRepository(remote RemoteRepository) error {
|
|||
}
|
||||
|
||||
func detectLocalRepoRoot(remotePath, repoPath string) string {
|
||||
remotePath = strings.TrimSuffix(remotePath, ".git")
|
||||
repoPath = strings.TrimSuffix(repoPath, ".git")
|
||||
remotePath = strings.TrimSuffix(strings.TrimSuffix(remotePath, "/"), ".git")
|
||||
repoPath = strings.TrimSuffix(strings.TrimSuffix(repoPath, "/"), ".git")
|
||||
pathParts := strings.Split(repoPath, "/")
|
||||
pathParts = pathParts[1:]
|
||||
for i := 0; i < len(pathParts); i++ {
|
||||
|
|
|
|||
|
|
@ -45,6 +45,16 @@ func TestDetectLocalRepoRoot(t *testing.T) {
|
|||
remotePath: "/path/to/repo.git",
|
||||
repoPath: "/path/to/repo.git",
|
||||
expect: "/path/to/repo",
|
||||
}, {
|
||||
name: "trailing slash",
|
||||
remotePath: "/path/to/repo/",
|
||||
repoPath: "/path/to/repo/",
|
||||
expect: "/path/to/repo",
|
||||
}, {
|
||||
name: ".git/ at the end",
|
||||
remotePath: "/path/to/repo.git/",
|
||||
repoPath: "/path/to/repo.git/",
|
||||
expect: "/path/to/repo",
|
||||
}}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
|
|
|||
Loading…
Reference in a new issue