Skip to content

Commit 7229d1f

Browse files
Walzpierrelalanne
authored andcommitted
feat(provider): Use the absolute path to infer the name of a local repository
1 parent 23a6403 commit 7229d1f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

provider/generic_repository.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ package provider
22

33
import (
44
"errors"
5+
"os"
6+
"path/filepath"
57
"srcfingerprint/cloner"
68
"strings"
79
"time"
10+
11+
log "github.com/sirupsen/logrus"
812
)
913

1014
// Repository Structure. Generic.
@@ -55,15 +59,25 @@ func (p *GenericProvider) Gather(user string) ([]GitRepository, error) {
5559
if p.options.RepositoryName != "" {
5660
name = p.options.RepositoryName
5761
} else {
62+
path := user
63+
if _, err := os.Stat(user); err == nil || !os.IsNotExist(err) {
64+
if absPath, err := filepath.Abs(user); err == nil {
65+
log.Debugf("`%v` is a local path, will use absolute path `%v`", user, absPath)
66+
path = absPath
67+
}
68+
}
69+
5870
// Split the repository URL or patch and use the last part
59-
parts := strings.Split(user, "/")
71+
parts := strings.Split(path, "/")
6072
if parts[len(parts)-1] == ".git" && len(parts) > 2 {
6173
// As "path/to/project/.git" is valid, we use the second to last part when the last part is ".git"
6274
name = parts[len(parts)-2]
6375
} else {
6476
name = parts[len(parts)-1]
6577
name = strings.TrimSuffix(name, ".git")
6678
}
79+
80+
log.Warnf("Name of the repository unspecified (see --repo-name). '%v' has been inferred from the object.", name)
6781
}
6882

6983
return []GitRepository{&Repository{

0 commit comments

Comments
 (0)