Skip to content

Commit

Permalink
Merge pull request #7659 from dolthub/macneale4/pull-panic
Browse files Browse the repository at this point in the history
Don't panic for conflicts in the `dolt pull` command
  • Loading branch information
macneale4 authored Mar 28, 2024
2 parents 801a82a + f589ad0 commit 9d9e9e5
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 8 deletions.
20 changes: 16 additions & 4 deletions go/cmd/dolt/commands/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,16 @@ func calculateMergeConflicts(queryist cli.Queryist, sqlCtx *sql.Context, mergeSt
}
for _, conflict := range dataConflicts {
tableName := conflict[0].(string)

cf, err := getInt64ColAsInt64(conflict[1])
if err != nil {
return nil, false, err
}

if ok := mergeStats[tableName]; ok != nil {
mergeStats[tableName].DataConflicts = int(conflict[1].(uint64))
mergeStats[tableName].DataConflicts = int(cf)
} else {
mergeStats[tableName] = &merge.MergeStats{DataConflicts: int(conflict[1].(uint64))}
mergeStats[tableName] = &merge.MergeStats{DataConflicts: int(cf)}
}
}

Expand All @@ -429,10 +435,16 @@ func calculateMergeConflicts(queryist cli.Queryist, sqlCtx *sql.Context, mergeSt
}
for _, conflict := range constraintViolations {
tableName := conflict[0].(string)

cf, err := getInt64ColAsInt64(conflict[1])
if err != nil {
return nil, false, err
}

if ok := mergeStats[tableName]; ok != nil {
mergeStats[tableName].ConstraintViolations = int(conflict[1].(uint64))
mergeStats[tableName].ConstraintViolations = int(cf)
} else {
mergeStats[tableName] = &merge.MergeStats{ConstraintViolations: int(conflict[1].(uint64))}
mergeStats[tableName] = &merge.MergeStats{ConstraintViolations: int(cf)}
}
}

Expand Down
60 changes: 59 additions & 1 deletion integration-tests/bats/fetch.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
load $BATS_TEST_DIRNAME/helper/common.bash

setup() {
setup_common
# See pull.bats. Can't use common remote server setup since we have multiple databases.
setup_no_dolt_init

TESTDIRS=$(pwd)/testdirs
mkdir -p $TESTDIRS/{rem1,repo1}

Expand Down Expand Up @@ -38,6 +40,9 @@ teardown() {

@test "fetch: basic fetch" {
cd repo2

setup_remote_server

dolt fetch

run dolt diff main origin/main
Expand All @@ -52,6 +57,9 @@ teardown() {

@test "fetch: fetch origin" {
cd repo2

setup_remote_server

dolt fetch origin

run dolt diff main origin/main
Expand All @@ -74,6 +82,9 @@ teardown() {
cd ..

cd repo2

setup_remote_server

dolt fetch origin main

run dolt diff main origin/main
Expand All @@ -99,6 +110,9 @@ teardown() {
dolt push test-remote main

cd ../repo2

setup_remote_server

dolt fetch test-remote

run dolt diff main test-remote/main
Expand All @@ -120,6 +134,9 @@ teardown() {
dolt push test-remote main

cd ../repo2

setup_remote_server

dolt fetch test-remote refs/heads/main:refs/remotes/test-remote/main

run dolt diff main test-remote/main
Expand All @@ -142,6 +159,9 @@ teardown() {
dolt push origin feature

cd ../repo2

setup_remote_server

dolt fetch origin feature

run dolt diff main origin/feature
Expand All @@ -161,6 +181,9 @@ teardown() {
dolt push origin v1

cd ../repo2

setup_remote_server

dolt fetch origin main

run dolt diff main v1
Expand All @@ -180,6 +203,9 @@ teardown() {
dolt push origin v1

cd ../repo2

setup_remote_server

dolt fetch origin refs/tags/v1:refs/tags/v1

run dolt diff main origin/v1
Expand All @@ -194,6 +220,9 @@ teardown() {

@test "fetch: fetch rename ref" {
cd repo2

setup_remote_server

dolt fetch test-remote refs/heads/main:refs/remotes/test-remote/other

run dolt diff main test-remote/other
Expand All @@ -209,6 +238,8 @@ teardown() {
@test "fetch: fetch override local branch" {
skip "todo more flexible refspec support"
cd repo2
setup_remote_server

dolt fetch origin main:refs/heads/main

dolt diff main origin/main
Expand All @@ -230,6 +261,8 @@ teardown() {
dolt push --force origin main
cd ../repo1

setup_remote_server

run dolt fetch origin main
[ "$status" -eq 0 ]

Expand All @@ -244,6 +277,10 @@ teardown() {
}

@test "fetch: fetch --prune deletes remote refs not on remote" {
if [ "$SQL_ENGINE" = "remote-engine" ]; then
skip "https://github.com/dolthub/dolt/issues/7657"
fi

mkdir firstRepo
mkdir secondRepo

Expand Down Expand Up @@ -304,6 +341,9 @@ teardown() {
@test "fetch: fetch unknown remote fails" {
cd repo2
dolt remote remove origin

setup_remote_server

run dolt fetch unknown
[ "$status" -eq 1 ]
[[ "$output" =~ "unknown remote" ]] || false
Expand All @@ -312,13 +352,19 @@ teardown() {
@test "fetch: fetch unknown remote with fetchspec fails" {
cd repo2
dolt remote remove origin

setup_remote_server

run dolt fetch unknown main
[ "$status" -eq 1 ]
[[ "$output" =~ "unknown remote" ]] || false
}

@test "fetch: fetch unknown ref fails" {
cd repo2

setup_remote_server

run dolt fetch origin unknown
[ "$status" -eq 1 ]
[[ "$output" =~ "invalid ref spec: 'unknown'" ]] || false
Expand All @@ -327,13 +373,19 @@ teardown() {
@test "fetch: fetch empty remote fails" {
cd repo2
dolt remote remove origin

setup_remote_server

run dolt fetch
[ "$status" -eq 1 ]
[[ "$output" =~ "unknown remote" ]] || false
}

@test "fetch: fetch empty ref fails" {
cd repo2

setup_remote_server

run dolt fetch origin ""
[ "$status" -eq 1 ]
[[ "$output" =~ "invalid fetch spec: ''" ]] || false
Expand All @@ -354,6 +406,9 @@ teardown() {

@test "fetch: output" {
cd repo2

setup_remote_server

run dolt fetch
[ "$status" -eq 0 ]
# fetch should print some kind of status message
Expand All @@ -362,6 +417,9 @@ teardown() {

@test "fetch: --silent suppresses progress message" {
cd repo2

setup_remote_server

run dolt fetch --silent
[ "$status" -eq 0 ]
! [[ "$output" =~ "Fetching..." ]] || false
Expand Down
2 changes: 2 additions & 0 deletions integration-tests/bats/helper/local-remote.bash
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ SKIP_SERVER_TESTS=$(cat <<-EOM
EOM
)

# Starts a remote server in the current working directory for the
# purposes of running dolt commands against a running sql-server.
setup_remote_server() {
script_name=$(basename ${BATS_TEST_FILENAME})
if [ "$SQL_ENGINE" = "remote-engine" ];
Expand Down
Loading

0 comments on commit 9d9e9e5

Please sign in to comment.