forked from toolshed/abra
Compare commits
3 Commits
0.8.1-beta
...
diffing-re
Author | SHA1 | Date | |
---|---|---|---|
608a52ada9
|
|||
f96bf9a8ac
|
|||
dcecf32999
|
@ -173,7 +173,7 @@ keys configured on your account.
|
|||||||
}
|
}
|
||||||
|
|
||||||
msg := "chore: publish new catalogue release changes"
|
msg := "chore: publish new catalogue release changes"
|
||||||
if err := gitPkg.Commit(cataloguePath, "**.json", msg, internal.Dry); err != nil {
|
if err := gitPkg.Commit(cataloguePath, msg, internal.Dry); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
40
cli/recipe/diff.go
Normal file
40
cli/recipe/diff.go
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package recipe
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path"
|
||||||
|
|
||||||
|
"coopcloud.tech/abra/cli/internal"
|
||||||
|
"coopcloud.tech/abra/pkg/autocomplete"
|
||||||
|
"coopcloud.tech/abra/pkg/config"
|
||||||
|
gitPkg "coopcloud.tech/abra/pkg/git"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/urfave/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
var recipeDiffCommand = cli.Command{
|
||||||
|
Name: "diff",
|
||||||
|
Usage: "Show unstaged changes in recipe config",
|
||||||
|
Description: "Due to limitations in our underlying Git dependency, this command requires /usr/bin/git.",
|
||||||
|
Aliases: []string{"d"},
|
||||||
|
ArgsUsage: "<recipe>",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
internal.DebugFlag,
|
||||||
|
internal.NoInputFlag,
|
||||||
|
},
|
||||||
|
Before: internal.SubCommandBefore,
|
||||||
|
BashComplete: autocomplete.RecipeNameComplete,
|
||||||
|
Action: func(c *cli.Context) error {
|
||||||
|
recipeName := c.Args().First()
|
||||||
|
|
||||||
|
if recipeName != "" {
|
||||||
|
internal.ValidateRecipe(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
|
||||||
|
if err := gitPkg.DiffUnstaged(recipeDir); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
@ -30,5 +30,7 @@ manner. Abra supports convenient automation for recipe maintainenace, see the
|
|||||||
recipeSyncCommand,
|
recipeSyncCommand,
|
||||||
recipeUpgradeCommand,
|
recipeUpgradeCommand,
|
||||||
recipeVersionCommand,
|
recipeVersionCommand,
|
||||||
|
recipeResetCommand,
|
||||||
|
recipeDiffCommand,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -106,6 +106,18 @@ your SSH keys configured on your account.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isClean, err := gitPkg.IsClean(recipe.Dir())
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !isClean {
|
||||||
|
logrus.Infof("%s currently has these unstaged changes 👇", recipe.Name)
|
||||||
|
if err := gitPkg.DiffUnstaged(recipe.Dir()); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if len(tags) > 0 {
|
if len(tags) > 0 {
|
||||||
logrus.Warnf("previous git tags detected, assuming this is a new semver release")
|
logrus.Warnf("previous git tags detected, assuming this is a new semver release")
|
||||||
if err := createReleaseFromPreviousTag(tagString, mainAppVersion, recipe, tags); err != nil {
|
if err := createReleaseFromPreviousTag(tagString, mainAppVersion, recipe, tags); err != nil {
|
||||||
@ -244,7 +256,7 @@ func commitRelease(recipe recipe.Recipe, tag string) error {
|
|||||||
|
|
||||||
msg := fmt.Sprintf("chore: publish %s release", tag)
|
msg := fmt.Sprintf("chore: publish %s release", tag)
|
||||||
repoPath := path.Join(config.RECIPES_DIR, recipe.Name)
|
repoPath := path.Join(config.RECIPES_DIR, recipe.Name)
|
||||||
if err := gitPkg.Commit(repoPath, ".", msg, internal.Dry); err != nil {
|
if err := gitPkg.Commit(repoPath, msg, internal.Dry); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
56
cli/recipe/reset.go
Normal file
56
cli/recipe/reset.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package recipe
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path"
|
||||||
|
|
||||||
|
"coopcloud.tech/abra/cli/internal"
|
||||||
|
"coopcloud.tech/abra/pkg/autocomplete"
|
||||||
|
"coopcloud.tech/abra/pkg/config"
|
||||||
|
"github.com/go-git/go-git/v5"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/urfave/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
var recipeResetCommand = cli.Command{
|
||||||
|
Name: "reset",
|
||||||
|
Usage: "Remove all unstaged changes from recipe config",
|
||||||
|
Description: "WARNING, this will delete your changes. Be Careful.",
|
||||||
|
Aliases: []string{"rs"},
|
||||||
|
ArgsUsage: "<recipe>",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
internal.DebugFlag,
|
||||||
|
internal.NoInputFlag,
|
||||||
|
},
|
||||||
|
Before: internal.SubCommandBefore,
|
||||||
|
BashComplete: autocomplete.RecipeNameComplete,
|
||||||
|
Action: func(c *cli.Context) error {
|
||||||
|
recipeName := c.Args().First()
|
||||||
|
|
||||||
|
if recipeName != "" {
|
||||||
|
internal.ValidateRecipe(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
repoPath := path.Join(config.RECIPES_DIR, recipeName)
|
||||||
|
repo, err := git.PlainOpen(repoPath)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ref, err := repo.Head()
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
worktree, err := repo.Worktree()
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
opts := &git.ResetOptions{Commit: ref.Hash(), Mode: git.HardReset}
|
||||||
|
if err := worktree.Reset(opts); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
@ -8,6 +8,7 @@ import (
|
|||||||
"coopcloud.tech/abra/cli/internal"
|
"coopcloud.tech/abra/cli/internal"
|
||||||
"coopcloud.tech/abra/pkg/autocomplete"
|
"coopcloud.tech/abra/pkg/autocomplete"
|
||||||
"coopcloud.tech/abra/pkg/config"
|
"coopcloud.tech/abra/pkg/config"
|
||||||
|
gitPkg "coopcloud.tech/abra/pkg/git"
|
||||||
"coopcloud.tech/tagcmp"
|
"coopcloud.tech/tagcmp"
|
||||||
"github.com/AlecAivazis/survey/v2"
|
"github.com/AlecAivazis/survey/v2"
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
@ -198,6 +199,17 @@ likely to change.
|
|||||||
logrus.Infof("dry run: not syncing label %s for recipe %s", nextTag, recipe.Name)
|
logrus.Infof("dry run: not syncing label %s for recipe %s", nextTag, recipe.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isClean, err := gitPkg.IsClean(recipe.Dir())
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
if !isClean {
|
||||||
|
logrus.Infof("%s currently has these unstaged changes 👇", recipe.Name)
|
||||||
|
if err := gitPkg.DiffUnstaged(recipe.Dir()); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"coopcloud.tech/abra/pkg/client"
|
"coopcloud.tech/abra/pkg/client"
|
||||||
"coopcloud.tech/abra/pkg/config"
|
"coopcloud.tech/abra/pkg/config"
|
||||||
"coopcloud.tech/abra/pkg/formatter"
|
"coopcloud.tech/abra/pkg/formatter"
|
||||||
|
gitPkg "coopcloud.tech/abra/pkg/git"
|
||||||
recipePkg "coopcloud.tech/abra/pkg/recipe"
|
recipePkg "coopcloud.tech/abra/pkg/recipe"
|
||||||
"coopcloud.tech/tagcmp"
|
"coopcloud.tech/tagcmp"
|
||||||
"github.com/AlecAivazis/survey/v2"
|
"github.com/AlecAivazis/survey/v2"
|
||||||
@ -326,6 +327,7 @@ You may invoke this command in "wizard" mode and be prompted for input:
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(string(jsonstring))
|
fmt.Println(string(jsonstring))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,6 +338,18 @@ You may invoke this command in "wizard" mode and be prompted for input:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isClean, err := gitPkg.IsClean(recipeDir)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
if !isClean {
|
||||||
|
logrus.Infof("%s currently has these unstaged changes 👇", recipe.Name)
|
||||||
|
if err := gitPkg.DiffUnstaged(recipeDir); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Commit runs a git commit
|
// Commit runs a git commit
|
||||||
func Commit(repoPath, glob, commitMessage string, dryRun bool) error {
|
func Commit(repoPath, commitMessage string, dryRun bool) error {
|
||||||
if commitMessage == "" {
|
if commitMessage == "" {
|
||||||
return fmt.Errorf("no commit message specified?")
|
return fmt.Errorf("no commit message specified?")
|
||||||
}
|
}
|
||||||
@ -33,17 +33,8 @@ func Commit(repoPath, glob, commitMessage string, dryRun bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !dryRun {
|
if !dryRun {
|
||||||
err = commitWorktree.AddGlob(glob)
|
// NOTE(d1): `All: true` does not include untracked files
|
||||||
if err != nil {
|
_, err = commitWorktree.Commit(commitMessage, &git.CommitOptions{All: true})
|
||||||
return err
|
|
||||||
}
|
|
||||||
logrus.Debugf("staged %s for commit", glob)
|
|
||||||
} else {
|
|
||||||
logrus.Debugf("dry run: did not stage %s for commit", glob)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !dryRun {
|
|
||||||
_, err = commitWorktree.Commit(commitMessage, &git.CommitOptions{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
42
pkg/git/diff.go
Normal file
42
pkg/git/diff.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package git
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
// getGitDiffArgs builds the `git diff` invocation args. It removes the usage
|
||||||
|
// of a pager and ensures that colours are specified even when Git might detect
|
||||||
|
// otherwise.
|
||||||
|
func getGitDiffArgs(repoPath string) []string {
|
||||||
|
return []string{
|
||||||
|
"-C",
|
||||||
|
repoPath,
|
||||||
|
"--no-pager",
|
||||||
|
"-c",
|
||||||
|
"color.diff=always",
|
||||||
|
"diff",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DiffUnstaged shows a `git diff`. Due to limitations in the underlying go-git
|
||||||
|
// library, this implementation requires the /usr/bin/git binary. It gracefully
|
||||||
|
// skips if it cannot find the command on the system.
|
||||||
|
func DiffUnstaged(path string) error {
|
||||||
|
if _, err := exec.LookPath("git"); err != nil {
|
||||||
|
logrus.Warnf("unable to locate git command, cannot output diff")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
gitDiffArgs := getGitDiffArgs(path)
|
||||||
|
diff, err := exec.Command("git", gitDiffArgs...).Output()
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Print(string(diff))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
ABRA_VERSION="0.8.0-beta"
|
ABRA_VERSION="0.8.1-beta"
|
||||||
ABRA_RELEASE_URL="https://git.coopcloud.tech/api/v1/repos/coop-cloud/abra/releases/tags/$ABRA_VERSION"
|
ABRA_RELEASE_URL="https://git.coopcloud.tech/api/v1/repos/coop-cloud/abra/releases/tags/$ABRA_VERSION"
|
||||||
RC_VERSION="0.8.0-beta"
|
RC_VERSION="0.8.1-beta"
|
||||||
RC_VERSION_URL="https://git.coopcloud.tech/api/v1/repos/coop-cloud/abra/releases/tags/$RC_VERSION"
|
RC_VERSION_URL="https://git.coopcloud.tech/api/v1/repos/coop-cloud/abra/releases/tags/$RC_VERSION"
|
||||||
|
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
|
21
tests/integration/recipe_diff.bats
Normal file
21
tests/integration/recipe_diff.bats
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
load "$PWD/tests/integration/helpers/common"
|
||||||
|
_common_setup
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "show unstaged changes" {
|
||||||
|
run $ABRA recipe diff "$TEST_RECIPE"
|
||||||
|
assert_success
|
||||||
|
refute_output --partial 'traefik.enable'
|
||||||
|
|
||||||
|
run sed -i '/traefik.enable=.*/d' "$ABRA_DIR/recipes/$TEST_RECIPE/compose.yml"
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run $ABRA recipe diff "$TEST_RECIPE"
|
||||||
|
assert_success
|
||||||
|
assert_output --partial 'traefik.enable'
|
||||||
|
|
||||||
|
_reset_recipe
|
||||||
|
}
|
25
tests/integration/recipe_reset.bats
Normal file
25
tests/integration/recipe_reset.bats
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
load "$PWD/tests/integration/helpers/common"
|
||||||
|
_common_setup
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "reset unstaged changes" {
|
||||||
|
run $ABRA recipe fetch "$TEST_RECIPE"
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run sed -i '/traefik.enable=.*/d' "$ABRA_DIR/recipes/$TEST_RECIPE/compose.yml"
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run $ABRA recipe diff "$TEST_RECIPE"
|
||||||
|
assert_success
|
||||||
|
assert_output --partial 'traefik.enable'
|
||||||
|
|
||||||
|
run $ABRA recipe reset "$TEST_RECIPE"
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run $ABRA recipe diff "$TEST_RECIPE"
|
||||||
|
assert_success
|
||||||
|
refute_output --partial 'traefik.enable'
|
||||||
|
}
|
Reference in New Issue
Block a user