Compare commits

..

1 Commits

Author SHA1 Message Date
536dd5f0ad
WIP: feat: cancel git clone ops gracefully
All checks were successful
continuous-integration/drone/push Build is passing
See #528
2025-04-22 22:47:17 +02:00
2 changed files with 18 additions and 1 deletions

View File

@ -25,7 +25,10 @@ func gitCloneIgnoreErr(err error) bool {
return false
}
// Clone runs a git clone which accounts for different default branches.
// Clone runs a git clone which accounts for different default branches. This
// function respects Ctrl+C (SIGINT) calls from the user, cancelling the
// context and deleting the (typically) half-baked clone of the repository.
// This avoids broken state for future clone / recipe ops.
func Clone(dir, url string) error {
ctx := context.Background()
ctx, cancelCtx := context.WithCancel(ctx)

View File

@ -10,6 +10,20 @@ import (
"coopcloud.tech/abra/pkg/config"
)
func TestClone(t *testing.T) {
dir := path.Join(config.RECIPES_DIR, "gitea")
os.RemoveAll(dir)
gitURL := fmt.Sprintf("%s/%s.git", config.REPOS_BASE_URL, "gitea")
if err := Clone(dir, gitURL); err != nil {
t.Fatalf("unable to git clone gitea: %s", err)
}
if _, err := os.Stat(dir); err != nil && os.IsNotExist(err) {
t.Fatal("gitea repo was not cloned successfully")
}
}
func TestCancelGitClone(t *testing.T) {
dir := path.Join(config.RECIPES_DIR, "gitea")
os.RemoveAll(dir)