Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/boxo-migrate: add an error message if we do not find a .git folder #263

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(`
Jorropo marked this conversation as resolved.
Show resolved Hide resolved
⚠️ 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/boxo@v0.8.0-rc3")
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"]