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 committed Apr 5, 2023
1 parent 085ed9d commit 3732723
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 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,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 {
Expand Down

0 comments on commit 3732723

Please sign in to comment.