Skip to content

Commit

Permalink
cmd/boxo-migrate: add an error message if we do not find a .git folder (
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorropo authored Apr 5, 2023
1 parent 085ed9d commit 9519a66
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions cmd/boxo-migrate/boxomigrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
"path/filepath"
"strings"

migrate "github.com/ipfs/boxo/cmd/boxo-migrate/internal"
Expand Down Expand Up @@ -55,9 +56,14 @@ func main() {
&cli.BoolFlag{
Name: "dryrun",
},
&cli.BoolFlag{
Name: "force",
Usage: "run even if no .git folder is found",
},
},
Action: func(clictx *cli.Context) error {
dryrun := clictx.Bool("dryrun")
force := clictx.Bool("force")
configFile := clictx.String("config")

migrator, err := buildMigrator(dryrun, configFile)
Expand All @@ -67,6 +73,34 @@ func main() {

fmt.Printf("\n\n")

if !force {
p, err := os.Getwd()
if err != nil {
return fmt.Errorf("failed to fetch current working directory: %w", err)
}

for {
g := filepath.Join(p, ".git")
_, err := os.Stat(g)
if err == nil {
break
}
newP := filepath.Dir(p)
if p == newP {
return fmt.Errorf(`
⚠️ Version Control System Check ⚠️
We couldn't locate a .git folder in any parent paths. We strongly recommend
using a Version Control System to help you easily compare and revert to a
previous state if needed, as this tool doesn't have an undo feature.
If you're using a different VCS or like to live dangerously, you can bypass this
check by adding the --force flag.`)
}
p = newP
}
}

if !dryrun {
err := migrator.GoGet("github.com/ipfs/[email protected]")
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/boxo-migrate/staticcheck.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
checks = ["-ST1005"]

0 comments on commit 9519a66

Please sign in to comment.