1 Commits

Author SHA1 Message Date
cacdbf673f update to use /Users/tai 2025-08-10 15:15:50 -07:00
3 changed files with 20 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ package cmd
import ( import (
"log" "log"
"os" "os"
"strings"
"github.com/taigrr/mg/parse" "github.com/taigrr/mg/parse"
) )
@@ -27,5 +28,11 @@ func GetConfig() parse.MGConfig {
} }
} }
} }
homeDir, _ := os.UserHomeDir()
for i, repo := range conf.Repos {
if strings.HasPrefix(repo.Path, "$HOME") {
conf.Repos[i].Path = strings.Replace(repo.Path, "$HOME", homeDir, 1)
}
}
return conf return conf
} }

View File

@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"log" "log"
"os" "os"
"strings"
git "github.com/go-git/go-git/v5" git "github.com/go-git/go-git/v5"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@@ -52,6 +53,16 @@ var registerCmd = &cobra.Command{
os.Exit(1) os.Exit(1)
} }
path = newPath.Filesystem.Root() path = newPath.Filesystem.Root()
homeDir, err := os.UserHomeDir()
if err != nil {
log.Println("Unable to get home directory")
os.Exit(1)
}
if strings.HasPrefix(path, homeDir) {
path = "$HOME" + path[len(homeDir):]
}
for _, v := range conf.Repos { for _, v := range conf.Repos {
if v.Path == path { if v.Path == path {
fmt.Printf("repo %s already registered\n", path) fmt.Printf("repo %s already registered\n", path)

View File

@@ -32,9 +32,9 @@ func (m MRConfig) ToMGConfig() MGConfig {
mgconf := MGConfig(m) mgconf := MGConfig(m)
for i, repo := range mgconf.Repos { for i, repo := range mgconf.Repos {
checkout := repo.Remote checkout := repo.Remote
if strings.HasPrefix(checkout, "git clone '") { if after, ok := strings.CutPrefix(checkout, "git clone '"); ok {
// git clone 'git@bitbucket.org:taigrr/mg.git' 'mg' // git clone 'git@bitbucket.org:taigrr/mg.git' 'mg'
remote := strings.TrimPrefix(checkout, "git clone '") remote := after
sp := strings.Split(remote, "' '") sp := strings.Split(remote, "' '")
remote = sp[0] remote = sp[0]
mgconf.Repos[i].Remote = remote mgconf.Repos[i].Remote = remote