aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorSteve Moyer <smoyer1@selesy.com>2022-05-27 13:33:44 -0400
committerSteve Moyer <smoyer1@selesy.com>2022-05-27 13:33:44 -0400
commit523a1481857e4e4e13c03a1d4d7630db73568694 (patch)
tree242c3af3cecf272a48eba52439809997d8fb133b /commands
parent1659fed99fdfeea53fa0d1da9da4fc3f7591116b (diff)
downloadgit-bug-523a1481857e4e4e13c03a1d4d7630db73568694.tar.gz
test(778): allow alternate CWD via context
Diffstat (limited to 'commands')
-rw-r--r--commands/env.go18
1 files changed, 16 insertions, 2 deletions
diff --git a/commands/env.go b/commands/env.go
index 98a7e1a5..4d90348f 100644
--- a/commands/env.go
+++ b/commands/env.go
@@ -46,12 +46,26 @@ func (o out) Println(a ...interface{}) {
_, _ = fmt.Fprintln(o, a...)
}
+func getCWD(cmd *cobra.Command, args []string) (string, error) {
+ cwd, ok := cmd.Context().Value("cwd").(string)
+ if cwd != "" && ok {
+ return cwd, nil
+ }
+
+ cwd, err := os.Getwd()
+ if err != nil {
+ return "", fmt.Errorf("unable to get the current working directory: %q", err)
+ }
+
+ return cwd, nil
+}
+
// loadRepo is a pre-run function that load the repository for use in a command
func loadRepo(env *Env) func(*cobra.Command, []string) error {
return func(cmd *cobra.Command, args []string) error {
- cwd, err := os.Getwd()
+ cwd, err := getCWD(cmd, args)
if err != nil {
- return fmt.Errorf("unable to get the current working directory: %q", err)
+ return err
}
env.repo, err = repository.OpenGoGitRepo(cwd, []repository.ClockLoader{bug.ClockLoader})