Skip to content

Commit

Permalink
Merge pull request #775 from bmeneg/fix-worktree-config
Browse files Browse the repository at this point in the history
config: fix worktree git config dir path
  • Loading branch information
bmeneg authored Jan 12, 2022
2 parents c89b6fa + 1a10490 commit bf54583
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,19 @@ func LoadMainConfig() (string, string, string, string, bool) {
}

// default path of worktree lab.toml file
var (
WorkTreePath string = ".git/lab"
WorkTreeName string = "lab"
)
var WorktreeConfigName string = "lab"

// worktreeConfigPath gets the current git config path using the
// `git rev-parse` command, which considers the worktree's gitdir path placed
// into the .git file.
func worktreeConfigPath() string {
gitDir, err := git.Dir()
if err != nil {
log.Fatal(err)
}

return gitDir + "/lab"
}

// LoadConfig loads a config file specified by configpath and configname.
// The configname must not have a '.toml' extension. If configpath and/or
Expand All @@ -352,10 +361,10 @@ func LoadConfig(configpath string, configname string) *viper.Viper {
targetConfig.SetConfigType("toml")

if configpath == "" {
configpath = WorkTreePath
configpath = worktreeConfigPath()
}
if configname == "" {
configname = WorkTreeName
configname = WorktreeConfigName
}
targetConfig.AddConfigPath(configpath)
targetConfig.SetConfigName(configname)
Expand Down

0 comments on commit bf54583

Please sign in to comment.