Allow `abra app new <git-url>` to use a recipe from outside the catalogue. On clone, a `.abra-source` sidecar records the canonical host/path name (the on-disk directory escapes "/" and "." lossily), and IsClean ignores it. When templating the app's .env, a `RECIPE=<canonical name>` line is injected so a later `abra app deploy`, possibly on another machine, re-fetches the recipe from the same git source. `recipe ls` now shows a source column listing these external recipes alongside catalogue ones. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package git
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/go-git/go-git/v5"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestIsClean(t *testing.T) {
|
|
isClean, err := IsClean("/tmp")
|
|
assert.Equal(t, isClean, false)
|
|
assert.True(t, errors.Is(err, git.ErrRepositoryNotExists))
|
|
}
|
|
|
|
// TestIsCleanIgnoresAbraSource confirms that the .abra-source sidecar
|
|
// file written by abra next to externally-cloned recipes does not cause
|
|
// IsClean to report the worktree as dirty.
|
|
func TestIsCleanIgnoresAbraSource(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
if _, err := git.PlainInit(dir, false); err != nil {
|
|
t.Fatalf("git init failed: %s", err)
|
|
}
|
|
|
|
sidecar := filepath.Join(dir, ".abra-source")
|
|
if err := os.WriteFile(sidecar, []byte("git.example.com/u/recipe\n"), 0o644); err != nil {
|
|
t.Fatalf("writing sidecar failed: %s", err)
|
|
}
|
|
|
|
isClean, err := IsClean(dir)
|
|
if err != nil {
|
|
t.Fatalf("IsClean returned error: %s", err)
|
|
}
|
|
assert.True(t, isClean, "expected worktree with only .abra-source to be reported clean")
|
|
|
|
// Sanity check: an unrelated untracked file should still mark it dirty.
|
|
other := filepath.Join(dir, "random.txt")
|
|
if err := os.WriteFile(other, []byte("hello"), 0o644); err != nil {
|
|
t.Fatalf("writing extra file failed: %s", err)
|
|
}
|
|
|
|
isClean, err = IsClean(dir)
|
|
if err != nil {
|
|
t.Fatalf("IsClean returned error: %s", err)
|
|
}
|
|
assert.False(t, isClean, "expected worktree with unrelated untracked file to be reported dirty")
|
|
}
|