From 373272384aaf3e15444a2d67744550659842e7b6 Mon Sep 17 00:00:00 2001 From: Jorropo Date: Wed, 5 Apr 2023 15:33:35 +0200 Subject: [PATCH] cmd/boxo-migrate: add an error message if we do not find a .git folder --- cmd/boxo-migrate/boxomigrate.go | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/cmd/boxo-migrate/boxomigrate.go b/cmd/boxo-migrate/boxomigrate.go index 2876203580..60ea97f725 100644 --- a/cmd/boxo-migrate/boxomigrate.go +++ b/cmd/boxo-migrate/boxomigrate.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "os" + "path/filepath" "strings" migrate "github.com/ipfs/boxo/cmd/boxo-migrate/internal" @@ -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) @@ -67,6 +73,35 @@ 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 + } + if p == "/" { + const msg = ` +⚠️ 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.` + // nolint: staticcheck + return fmt.Errorf(msg) + } + p = filepath.Dir(p) + } + } + if !dryrun { err := migrator.GoGet("github.com/ipfs/boxo@v0.8.0-rc3") if err != nil {