From 26b581b5db64a0c992c0c6714fbb37c2c677bef4 Mon Sep 17 00:00:00 2001 From: jolheiser Date: Thu, 3 Aug 2023 15:15:28 -0500 Subject: [PATCH] chore: update readme and renormalize on init Signed-off-by: jolheiser --- README.md | 6 ++++-- cmd/init.go | 20 ++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7dfc246..11ba903 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Echoed from the original project: > > The one use-case where it makes sense to use `git-age` instead is when you want to keep some files secret on a (potentially public) git remote, but you need to have the plaintext in the local working tree because you cannot hook into the above tools for your workflow. **Being lazy is not an excuse to use this software.** -## Install +## Adding git-age to a new repository 1. Install `git-age` in your `PATH` 2. `git age init` @@ -18,7 +18,9 @@ Echoed from the original project: - `git age ident key.txt` - `git age ident ssh` 4. Set up your config ([example](.git-age.yaml)) -5. Use git like normal. +5. Add your secrets to `.gitattributes` + `secret.txt diff=git-age filter=git-age` +6. Use git like normal. ## Decrypting an existing repository diff --git a/cmd/init.go b/cmd/init.go index e450af1..4aae21e 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -2,7 +2,9 @@ package cmd import ( "bytes" + "errors" "fmt" + "io/fs" "os" "os/exec" "path/filepath" @@ -41,6 +43,9 @@ func actionInit(ctx *cli.Context) error { cfg, err := LoadConfig() if err != nil { + if errors.Is(err, fs.ErrNotExist) { + return nil + } return err } dir, err := gitBaseDir() @@ -61,13 +66,13 @@ func actionInit(ctx *cli.Context) error { } var buf bytes.Buffer - cmd := exec.Command(exe, args...) - cmd.Stdin = bytes.NewReader(content) - cmd.Stdout = &buf + c := exec.Command(exe, args...) + c.Stdin = bytes.NewReader(content) + c.Stdout = &buf if debug { - cmd.Stderr = os.Stderr + c.Stderr = os.Stderr } - if err := cmd.Run(); err != nil { + if err := c.Run(); err != nil { if debug { fmt.Fprintf(os.Stderr, "could not smudge file: %v\n", err) } @@ -78,8 +83,11 @@ func actionInit(ctx *cli.Context) error { if err != nil { return err } - defer fi.Close() fi.Write(buf.Bytes()) + if err := fi.Close(); err != nil { + return err + } + cmd("git", "add", "--renormalize", apn) return nil }(); err != nil {