Skip to content

Commit

Permalink
Merge pull request #6372 from dolthub/zachmu/b6365
Browse files Browse the repository at this point in the history
Fixed backup to require a dolt directory
  • Loading branch information
zachmu authored Jul 22, 2023
2 parents d75db30 + 951c551 commit e7391dd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
7 changes: 7 additions & 0 deletions go/cmd/dolt/commands/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ func (cmd BackupCmd) Exec(ctx context.Context, commandStr string, args []string,

var verr errhand.VerboseError

// All the sub commands except `restore` require a valid environment
if apr.NArg() == 0 || apr.Arg(0) != cli.RestoreBackupId {
if !cli.CheckEnvIsValid(dEnv) {
return 2
}
}

switch {
case apr.NArg() == 0:
verr = printBackups(dEnv, apr)
Expand Down
27 changes: 26 additions & 1 deletion integration-tests/bats/backup.bats
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ teardown() {
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 1 ]
[[ "$output" =~ "bac1" ]] || false

mkdir newdir && cd newdir
run dolt backup add bac1 file://../bac1
[ "$status" -ne 0 ]
}

@test "backup: remove named backup" {
Expand All @@ -48,6 +52,10 @@ teardown() {
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 0 ]
[[ ! "$output" =~ "bac1" ]] || false

mkdir newdir && cd newdir
run dolt backup remove bac1
[ "$status" -ne 0 ]
}

@test "backup: rm named backup" {
Expand All @@ -64,6 +72,10 @@ teardown() {
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 0 ]
[[ ! "$output" =~ "bac1" ]] || false

mkdir newdir && cd newdir
run dolt backup rm bac1
[ "$status" -ne 0 ]
}

@test "backup: removing a backup with the same name as a remote does not impact remote tracking refs" {
Expand All @@ -84,14 +96,20 @@ teardown() {
dolt backup sync bac1

cd ..
run dolt backup restore file://./bac1 repo2
dolt backup restore file://./bac1 repo2
cd repo2
run dolt ls
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 2 ]
[[ "$output" =~ "t1" ]] || false
}

@test "backup: sync in a non-dolt directory" {
mkdir newdir && cd newdir
run dolt backup sync bac1
[ "$status" -ne 0 ]
}

@test "backup: sync feature to backup" {
cd repo1
dolt backup add bac1 file://../bac1
Expand Down Expand Up @@ -251,3 +269,10 @@ teardown() {
[ "${#lines[@]}" -eq 2 ]
[[ "$output" =~ "t1" ]] || false
}

@test "backup: sync-url in a non-dolt directory" {
mkdir newdir && cd newdir
run dolt backup sync-url file://../bac1
[ "$status" -ne 0 ]
}

0 comments on commit e7391dd

Please sign in to comment.