-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ability to configure repository clone directory (#366)
- Loading branch information
1 parent
b556a44
commit 6345c6b
Showing
10 changed files
with
174 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func main() { | ||
path, _ := os.Getwd() | ||
fmt.Println("Current path:", path) | ||
err := os.WriteFile("pwd.txt", []byte(path), 0600) | ||
if err != nil { | ||
fmt.Println("Could not write to pwd.txt:", err) | ||
return | ||
} | ||
fmt.Println("Wrote to pwd.txt") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,8 @@ func TestStory(t *testing.T) { | |
runOutFile := filepath.Join(tmpDir, "run-log.txt") | ||
|
||
command := cmd.RootCmd() | ||
command.SetArgs([]string{"run", | ||
command.SetArgs([]string{ | ||
"run", | ||
"--output", runOutFile, | ||
"--author-name", "Test Author", | ||
"--author-email", "[email protected]", | ||
|
@@ -75,7 +76,8 @@ Repositories with a successful run: | |
statusOutFile := filepath.Join(tmpDir, "status-log.txt") | ||
|
||
command = cmd.RootCmd() | ||
command.SetArgs([]string{"status", | ||
command.SetArgs([]string{ | ||
"status", | ||
"--output", statusOutFile, | ||
"-B", "custom-branch-name", | ||
}) | ||
|
@@ -96,7 +98,8 @@ Repositories with a successful run: | |
mergeLogFile := filepath.Join(tmpDir, "merge-log.txt") | ||
|
||
command = cmd.RootCmd() | ||
command.SetArgs([]string{"merge", | ||
command.SetArgs([]string{ | ||
"merge", | ||
"--log-file", mergeLogFile, | ||
"-B", "custom-branch-name", | ||
}) | ||
|
@@ -115,7 +118,8 @@ Repositories with a successful run: | |
afterMergeStatusOutFile := filepath.Join(tmpDir, "after-merge-status-log.txt") | ||
|
||
command = cmd.RootCmd() | ||
command.SetArgs([]string{"status", | ||
command.SetArgs([]string{ | ||
"status", | ||
"--output", afterMergeStatusOutFile, | ||
"-B", "custom-branch-name", | ||
}) | ||
|
@@ -133,7 +137,8 @@ Repositories with a successful run: | |
closeLogFile := filepath.Join(tmpDir, "close-log.txt") | ||
|
||
command = cmd.RootCmd() | ||
command.SetArgs([]string{"close", | ||
command.SetArgs([]string{ | ||
"close", | ||
"--log-file", closeLogFile, | ||
"-B", "custom-branch-name", | ||
}) | ||
|
@@ -152,7 +157,8 @@ Repositories with a successful run: | |
afterCloseStatusOutFile := filepath.Join(tmpDir, "after-close-status-log.txt") | ||
|
||
command = cmd.RootCmd() | ||
command.SetArgs([]string{"status", | ||
command.SetArgs([]string{ | ||
"status", | ||
"--output", afterCloseStatusOutFile, | ||
"-B", "custom-branch-name", | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"io" | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
@@ -1187,6 +1188,74 @@ Repositories with a successful run: | |
}, | ||
}, | ||
|
||
{ | ||
name: "custom clone dir with relative path", | ||
vcCreate: func(t *testing.T) *vcmock.VersionController { | ||
return &vcmock.VersionController{ | ||
Repositories: []vcmock.Repository{ | ||
createRepo(t, "owner", "should-change", "i like apples"), | ||
}, | ||
} | ||
}, | ||
args: []string{ | ||
"run", | ||
"--author-name", "Test Author", | ||
"--author-email", "[email protected]", | ||
"-B", "clone-dir-branch-name", | ||
"-m", "clone dir message", | ||
"--clone-dir", "./tmp-test", | ||
fmt.Sprintf("go run %s", normalizePath(filepath.Join(workingDir, "scripts/pwd/main.go"))), | ||
}, | ||
verify: func(t *testing.T, vcMock *vcmock.VersionController, runData runData) { | ||
require.Len(t, vcMock.PullRequests, 1) | ||
expectedPath := filepath.Join(workingDir, "tmp-test") | ||
|
||
// Check the path in the logs | ||
assert.Contains(t, runData.logOut, "Current path: "+strings.ReplaceAll(expectedPath, `\`, `\\`)) | ||
|
||
changeBranch(t, vcMock.Repositories[0].Path, "clone-dir-branch-name", false) | ||
pathInFile := readFile(t, vcMock.Repositories[0].Path, "pwd.txt") | ||
assert.True(t, strings.HasPrefix(pathInFile, expectedPath)) | ||
}, | ||
}, | ||
|
||
{ | ||
name: "custom clone dir with absolute path", | ||
vcCreate: func(t *testing.T) *vcmock.VersionController { | ||
return &vcmock.VersionController{ | ||
Repositories: []vcmock.Repository{ | ||
createRepo(t, "owner", "should-change", "i like apples"), | ||
}, | ||
} | ||
}, | ||
args: []string{ | ||
"run", | ||
"--author-name", "Test Author", | ||
"--author-email", "[email protected]", | ||
"-B", "clone-dir-branch-name", | ||
"-m", "clone dir message", | ||
"--clone-dir", filepath.Join(os.TempDir(), "tmp-test"), | ||
fmt.Sprintf("go run %s", normalizePath(filepath.Join(workingDir, "scripts/pwd/main.go"))), | ||
}, | ||
verify: func(t *testing.T, vcMock *vcmock.VersionController, runData runData) { | ||
require.Len(t, vcMock.PullRequests, 1) | ||
|
||
tmpDir := os.TempDir() | ||
// Fix for MacOS (darwin) where the tmp directory is aliased under two different directories | ||
if runtime.GOOS == "darwin" { | ||
tmpDir = filepath.Join("/private", tmpDir) | ||
} | ||
|
||
expectedPath := filepath.Join(tmpDir, "tmp-test") | ||
|
||
assert.Contains(t, runData.logOut, "Current path: "+strings.ReplaceAll(expectedPath, `\`, `\\`)) | ||
|
||
changeBranch(t, vcMock.Repositories[0].Path, "clone-dir-branch-name", false) | ||
pathInFile := readFile(t, vcMock.Repositories[0].Path, "pwd.txt") | ||
assert.True(t, strings.HasPrefix(pathInFile, expectedPath)) | ||
}, | ||
}, | ||
|
||
{ | ||
name: "fork conflicts with pushOnly", | ||
vcCreate: func(t *testing.T) *vcmock.VersionController { | ||
|
@@ -1277,9 +1346,10 @@ Repositories with a successful run: | |
|
||
outFile, err := os.CreateTemp(os.TempDir(), "multi-gitter-test-output") | ||
require.NoError(t, err) | ||
// defer os.Remove(outFile.Name()) | ||
defer os.Remove(outFile.Name()) | ||
|
||
vc := test.vcCreate(t) | ||
|
||
defer vc.Clean() | ||
|
||
cmd.OverrideVersionController = vc | ||
|