forked from toolshed/abra
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			app-volume
			...
			recipe-ini
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| c23d2d34b9 | 
| @ -238,6 +238,22 @@ var RemoteUserFlag = &cli.StringFlag{ | |||||||
| 	Destination: &RemoteUser, | 	Destination: &RemoteUser, | ||||||
| } | } | ||||||
|  |  | ||||||
|  | var GitName string | ||||||
|  | var GitNameFlag = &cli.StringFlag{ | ||||||
|  | 	Name:        "git-name, gn", | ||||||
|  | 	Value:       "", | ||||||
|  | 	Usage:       "Git (user) name to do commits with", | ||||||
|  | 	Destination: &GitName, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | var GitEmail string | ||||||
|  | var GitEmailFlag = &cli.StringFlag{ | ||||||
|  | 	Name:        "git-email, ge", | ||||||
|  | 	Value:       "", | ||||||
|  | 	Usage:       "Git email name to do commits with", | ||||||
|  | 	Destination: &GitEmail, | ||||||
|  | } | ||||||
|  |  | ||||||
| // SubCommandBefore wires up pre-action machinery (e.g. --debug handling). | // SubCommandBefore wires up pre-action machinery (e.g. --debug handling). | ||||||
| func SubCommandBefore(c *cli.Context) error { | func SubCommandBefore(c *cli.Context) error { | ||||||
| 	if Debug { | 	if Debug { | ||||||
|  | |||||||
| @ -4,7 +4,6 @@ import ( | |||||||
| 	"bytes" | 	"bytes" | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io/ioutil" |  | ||||||
| 	"os" | 	"os" | ||||||
| 	"path" | 	"path" | ||||||
| 	"text/template" | 	"text/template" | ||||||
| @ -37,6 +36,8 @@ var recipeNewCommand = cli.Command{ | |||||||
| 		internal.DebugFlag, | 		internal.DebugFlag, | ||||||
| 		internal.NoInputFlag, | 		internal.NoInputFlag, | ||||||
| 		internal.OfflineFlag, | 		internal.OfflineFlag, | ||||||
|  | 		internal.GitNameFlag, | ||||||
|  | 		internal.GitEmailFlag, | ||||||
| 	}, | 	}, | ||||||
| 	Before:    internal.SubCommandBefore, | 	Before:    internal.SubCommandBefore, | ||||||
| 	Usage:     "Create a new recipe", | 	Usage:     "Create a new recipe", | ||||||
| @ -92,14 +93,14 @@ recipe and domain in the sample environment config). | |||||||
| 				logrus.Fatal(err) | 				logrus.Fatal(err) | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			if err := ioutil.WriteFile(path, templated.Bytes(), 0644); err != nil { | 			if err := os.WriteFile(path, templated.Bytes(), 0644); err != nil { | ||||||
| 				logrus.Fatal(err) | 				logrus.Fatal(err) | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		newGitRepo := path.Join(config.RECIPES_DIR, recipeName) | 		newGitRepo := path.Join(config.RECIPES_DIR, recipeName) | ||||||
| 		if err := git.Init(newGitRepo, true); err != nil { | 		if err := git.Init(newGitRepo, true, internal.GitName, internal.GitEmail); err != nil { | ||||||
| 			logrus.Fatal(err) | 			logrus.Fatal(err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | |||||||
| @ -1,35 +1,41 @@ | |||||||
| package git | package git | ||||||
|  |  | ||||||
| import ( | import ( | ||||||
|  | 	"fmt" | ||||||
|  |  | ||||||
| 	"github.com/go-git/go-git/v5" | 	"github.com/go-git/go-git/v5" | ||||||
| 	gitPkg "github.com/go-git/go-git/v5" | 	"github.com/go-git/go-git/v5/plumbing/object" | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // Init inits a new repo and commits all the stuff if you want | // Init inits a new repo and commits all the stuff if you want | ||||||
| func Init(repoPath string, commit bool) error { | func Init(repoPath string, commit bool, gitName, gitEmail string) error { | ||||||
| 	if _, err := gitPkg.PlainInit(repoPath, false); err != nil { | 	if _, err := git.PlainInit(repoPath, false); err != nil { | ||||||
| 		logrus.Fatal(err) | 		return fmt.Errorf("git init: %s", err) | ||||||
| 	} | 	} | ||||||
| 	logrus.Debugf("initialised new git repo in %s", repoPath) | 	logrus.Debugf("initialised new git repo in %s", repoPath) | ||||||
|  |  | ||||||
| 	if commit { | 	if commit { | ||||||
| 		commitRepo, err := git.PlainOpen(repoPath) | 		commitRepo, err := git.PlainOpen(repoPath) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			logrus.Fatal(err) | 			return fmt.Errorf("git open: %s", err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		commitWorktree, err := commitRepo.Worktree() | 		commitWorktree, err := commitRepo.Worktree() | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			logrus.Fatal(err) | 			return fmt.Errorf("git worktree: %s", err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if err := commitWorktree.AddWithOptions(&git.AddOptions{All: true}); err != nil { | 		if err := commitWorktree.AddWithOptions(&git.AddOptions{All: true}); err != nil { | ||||||
| 			return err | 			return fmt.Errorf("git add: %s", err) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if _, err = commitWorktree.Commit("init", &git.CommitOptions{}); err != nil { | 		var author *object.Signature | ||||||
| 			return err | 		if gitName != "" && gitEmail != "" { | ||||||
|  | 			author = &object.Signature{Name: gitName, Email: gitEmail} | ||||||
|  | 		} | ||||||
|  | 		if _, err = commitWorktree.Commit("init", &git.CommitOptions{Author: author}); err != nil { | ||||||
|  | 			return fmt.Errorf("git commit: %s", err) | ||||||
| 		} | 		} | ||||||
| 		logrus.Debugf("init committed all files for new git repo in %s", repoPath) | 		logrus.Debugf("init committed all files for new git repo in %s", repoPath) | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -23,14 +23,14 @@ teardown(){ | |||||||
| } | } | ||||||
|  |  | ||||||
| @test "create new recipe" { | @test "create new recipe" { | ||||||
|   run $ABRA recipe new foobar |   run $ABRA recipe new foobar --git-name foo --git-email foo@example.com | ||||||
|   assert_success |   assert_success | ||||||
|   assert_output --partial 'Your new foobar recipe has been created' |   assert_output --partial 'Your new foobar recipe has been created' | ||||||
|   assert_exists "$ABRA_DIR/recipes/foobar" |   assert_exists "$ABRA_DIR/recipes/foobar" | ||||||
| } | } | ||||||
|  |  | ||||||
| @test "create new app from new recipe" { | @test "create new app from new recipe" { | ||||||
|   run $ABRA recipe new foobar |   run $ABRA recipe new foobar --git-name foo --git-email foo@example.com | ||||||
|   assert_success |   assert_success | ||||||
|  |  | ||||||
|   run $ABRA app new foobar \ |   run $ABRA app new foobar \ | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user