Skip to content

Commit 2acc23f

Browse files
Merge pull request #100 from pluralsh/mjg/eng-119-cli-fix-file-encryption-detection
Add repair command in the cli
2 parents 086db1d + c51bbab commit 2acc23f

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

cmd/plural/git.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,20 @@ package main
33
import (
44
"os"
55
"os/exec"
6+
"github.com/urfave/cli"
7+
"github.com/pluralsh/plural/pkg/utils/git"
68
)
79

10+
11+
func handleRepair(c *cli.Context) error {
12+
repoRoot, err := git.Root()
13+
if err != nil {
14+
return err
15+
}
16+
17+
return git.Repair(repoRoot)
18+
}
19+
820
func gitConfig(name, val string) error {
921
cmd := gitCommand("config", name, val)
1022
return cmd.Run()

cmd/plural/plural.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ func main() {
217217
Action: handleImport,
218218
Category: "User Profile",
219219
},
220+
{
221+
Name: "repair",
222+
Usage: "commits any new encrypted changes in your local workspace automatically",
223+
Action: handleRepair,
224+
Category: "WORKSPACE",
225+
},
220226
{
221227
Name: "serve",
222228
Usage: "launch the server",

pkg/utils/git/remote.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package git
33
import (
44
"fmt"
55
"os"
6+
"strings"
67

78
gogit "github.com/go-git/go-git/v5"
89
"github.com/go-git/go-git/v5/plumbing/transport"
@@ -17,6 +18,20 @@ func Clone(auth transport.AuthMethod, url, path string) (*gogit.Repository, erro
1718
})
1819
}
1920

21+
func Repair(root string) error {
22+
_, err := git(root, "diff-index", "--quiet", "HEAD", "--")
23+
if err == nil {
24+
return nil
25+
}
26+
27+
diff, _ := git(root, "diff")
28+
if strings.TrimSpace(diff) == "" && err != nil {
29+
return Sync(root, "committing new encrypted files", false)
30+
}
31+
32+
return fmt.Errorf("There were non-repairable changes in your local git repository, you'll need to investigate them manually")
33+
}
34+
2035
func Sync(root, msg string, force bool) error {
2136
if res, err := git(root, "add", "."); err != nil {
2237
return errors.ErrorWrap(fmt.Errorf(res), "`git add .` failed")

0 commit comments

Comments
 (0)