Skip to content
Snippets Groups Projects
Unverified Commit 331e6dc5 authored by Steve Moyer's avatar Steve Moyer
Browse files

feat(cli): allow an alternate Git repository path to be specified

A  flag was added that shares the same semantics as the Git's  flag

Resolves #1467O
parent b80d27c2
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,7 @@ type Env struct { ...@@ -24,6 +24,7 @@ type Env struct {
In In In In
Out Out Out Out
Err Out Err Out
RepoPath []string
} }
func NewEnv() *Env { func NewEnv() *Env {
......
...@@ -3,6 +3,7 @@ package execenv ...@@ -3,6 +3,7 @@ package execenv
import ( import (
"fmt" "fmt"
"os" "os"
"path/filepath"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/vbauerster/mpb/v8" "github.com/vbauerster/mpb/v8"
...@@ -17,15 +18,15 @@ import ( ...@@ -17,15 +18,15 @@ import (
// LoadRepo is a pre-run function that load the repository for use in a command // LoadRepo is a pre-run function that load the repository for use in a command
func LoadRepo(env *Env) func(*cobra.Command, []string) error { func LoadRepo(env *Env) func(*cobra.Command, []string) error {
return func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error {
cwd, err := os.Getwd() repoPath, err := getRepoPath(env)
if err != nil { if err != nil {
return fmt.Errorf("unable to get the current working directory: %q", err) return err
} }
// Note: we are not loading clocks here because we assume that LoadRepo is only used // Note: we are not loading clocks here because we assume that LoadRepo is only used
// when we don't manipulate entities, or as a child call of LoadBackend which will // when we don't manipulate entities, or as a child call of LoadBackend which will
// read all clocks anyway. // read all clocks anyway.
env.Repo, err = repository.OpenGoGitRepo(cwd, gitBugNamespace, nil) env.Repo, err = repository.OpenGoGitRepo(repoPath, gitBugNamespace, nil)
if err == repository.ErrNotARepo { if err == repository.ErrNotARepo {
return fmt.Errorf("%s must be run from within a git Repo", RootCommandName) return fmt.Errorf("%s must be run from within a git Repo", RootCommandName)
} }
...@@ -171,3 +172,15 @@ func CacheBuildProgressBar(env *Env, events chan cache.BuildEvent) error { ...@@ -171,3 +172,15 @@ func CacheBuildProgressBar(env *Env, events chan cache.BuildEvent) error {
return nil return nil
} }
func getRepoPath(env *Env) (string, error) {
if len(env.RepoPath) > 0 {
return filepath.Join(env.RepoPath...), nil
}
cwd, err := os.Getwd()
if err != nil {
return "", fmt.Errorf("unable to get the current working directory: %q", err)
}
return cwd, nil
}
...@@ -5,10 +5,10 @@ import ( ...@@ -5,10 +5,10 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/git-bug/git-bug/commands/bridge" bridgecmd "github.com/git-bug/git-bug/commands/bridge"
"github.com/git-bug/git-bug/commands/bug" bugcmd "github.com/git-bug/git-bug/commands/bug"
"github.com/git-bug/git-bug/commands/execenv" "github.com/git-bug/git-bug/commands/execenv"
"github.com/git-bug/git-bug/commands/user" usercmd "github.com/git-bug/git-bug/commands/user"
) )
func NewRootCommand(version string) *cobra.Command { func NewRootCommand(version string) *cobra.Command {
...@@ -55,6 +55,7 @@ the same git remote you are already using to collaborate with other people. ...@@ -55,6 +55,7 @@ the same git remote you are already using to collaborate with other people.
} }
env := execenv.NewEnv() env := execenv.NewEnv()
cmd.PersistentFlags().StringArrayVarP(&env.RepoPath, "repo-path", "C", []string{}, "Path to the git repository")
addCmdWithGroup(bugcmd.NewBugCommand(env), entityGroup) addCmdWithGroup(bugcmd.NewBugCommand(env), entityGroup)
addCmdWithGroup(usercmd.NewUserCommand(env), entityGroup) addCmdWithGroup(usercmd.NewUserCommand(env), entityGroup)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment