aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorSteve Moyer <smoyer1@selesy.com>2022-06-07 07:45:30 -0400
committerSteve Moyer <smoyer1@selesy.com>2022-06-07 07:45:30 -0400
commit6ec7d67ea14d236c65b3d93bb4c4501432696659 (patch)
treec1e7ba7b6ceecb6763675ac8c0e3bf2bf9b1734d /commands
parentf0f52472dc570baede240572dba8392cf75cad5d (diff)
downloadgit-bug-6ec7d67ea14d236c65b3d93bb4c4501432696659.tar.gz
test(808): document getCWD() and clean-up arguments
Diffstat (limited to 'commands')
-rw-r--r--commands/env.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/commands/env.go b/commands/env.go
index c2128780..9be20c14 100644
--- a/commands/env.go
+++ b/commands/env.go
@@ -48,7 +48,13 @@ func (o out) Println(a ...interface{}) {
_, _ = fmt.Fprintln(o, a...)
}
-func getCWD(cmd *cobra.Command, args []string) (string, error) {
+// getCWD returns the current working directory. Normal operation simply
+// returns the working directory reported by the OS (as an OS-compatible
+// filepath.) During tests, temporary repositories are created outside
+// the test execution's CWD. In this case, it's possible to provide an
+// alternate CWD filepath by adding a value to the command's context
+// with the key "cwd".
+func getCWD(cmd *cobra.Command) (string, error) {
cwd, ok := cmd.Context().Value("cwd").(string)
if cwd != "" && ok {
return cwd, nil
@@ -65,7 +71,7 @@ func getCWD(cmd *cobra.Command, args []string) (string, error) {
// 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 := getCWD(cmd, args)
+ cwd, err := getCWD(cmd)
if err != nil {
return err
}