Commit 2b17497
Changed files (3)
pkg/templates/templates.go
@@ -2,7 +2,6 @@ package templates
import (
"embed"
- _ "embed"
. "html/template"
"path/filepath"
"time"
config.go
@@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
+ "os/exec"
"path/filepath"
"strings"
@@ -102,22 +103,11 @@ func normalizeRepoPath(path *string) error {
}
func autoDefaultBranchName(repoPath string) string {
- candidates := []string{"master", "main"}
- for _, name := range candidates {
- refPath := filepath.Join(repoPath, ".git", "refs", "heads", name)
- if _, err := os.Stat(refPath); err == nil {
- return name
- }
+ cmd := exec.Command("git", "symbolic-ref", "--short", "HEAD")
+ cmd.Dir = repoPath
+ out, err := cmd.Output()
+ if err != nil {
+ return ""
}
- return ""
-}
-
-func sanitizeSlug(name string) string {
- return strings.NewReplacer(
- " ", "-",
- "_", "-",
- "/", "-",
- "\\", "-",
- ".", "-",
- ).Replace(strings.ToLower(name))
+ return strings.TrimSpace(string(out))
}
main.go
@@ -137,13 +137,13 @@ func main() {
})
}
} else if cfg.Repo != nil {
- inputPath, err := repoInputPath()
- if err != nil {
- panic(err)
- }
- repoPath := inputPath
- if repoPath == "." {
- repoPath = cfg.Repo.Path
+ repoPath := cfg.Repo.Path
+ if len(flag.Args()) > 0 {
+ absPath, err := filepath.Abs(flag.Args()[0])
+ if err != nil {
+ panic(err)
+ }
+ repoPath = absPath
}
repoName := flagName
if repoName == "" {