diff --git a/go/cmd/dolt/commands/push.go b/go/cmd/dolt/commands/push.go index ec73595a57..1099f8b7e1 100644 --- a/go/cmd/dolt/commands/push.go +++ b/go/cmd/dolt/commands/push.go @@ -303,7 +303,6 @@ func stopProgFuncs(cancel context.CancelFunc, wg *sync.WaitGroup, progChan chan close(pullerEventCh) wg.Wait() - cli.Println() } func bytesPerSec(bytes uint64, start time.Time) string { diff --git a/go/libraries/doltcore/doltdb/doltdb.go b/go/libraries/doltcore/doltdb/doltdb.go index 3433e79344..5149b7ee2b 100644 --- a/go/libraries/doltcore/doltdb/doltdb.go +++ b/go/libraries/doltcore/doltdb/doltdb.go @@ -1278,10 +1278,7 @@ func (ddb *DoltDB) PushChunksForRefHash(ctx context.Context, tempDir string, src func (ddb *DoltDB) PullChunks(ctx context.Context, tempDir string, srcDB *DoltDB, stRef types.Ref, progChan chan datas.PullProgress, pullerEventCh chan datas.PullerEvent) error { if datas.CanUsePuller(srcDB.db) && datas.CanUsePuller(ddb.db) { puller, err := datas.NewPuller(ctx, tempDir, defaultChunksPerTF, srcDB.db, ddb.db, stRef.TargetHash(), pullerEventCh) - - if err == datas.ErrDBUpToDate { - return nil - } else if err != nil { + if err != nil { return err } diff --git a/go/libraries/doltcore/env/actions/commitwalk/commitwalk_test.go b/go/libraries/doltcore/env/actions/commitwalk/commitwalk_test.go index 05878ed8db..bf67b3ad70 100644 --- a/go/libraries/doltcore/env/actions/commitwalk/commitwalk_test.go +++ b/go/libraries/doltcore/env/actions/commitwalk/commitwalk_test.go @@ -231,6 +231,9 @@ func mustForkDB(t *testing.T, fromDB *doltdb.DoltDB, bn string, cm *doltdb.Commi } }() err = forkEnv.DoltDB.PullChunks(context.Background(), "", fromDB, stref, p1, p2) + if err == datas.ErrDBUpToDate { + err = nil + } require.NoError(t, err) err = forkEnv.DoltDB.SetHead(context.Background(), ref.NewBranchRef(bn), stref) require.NoError(t, err) diff --git a/go/libraries/doltcore/env/actions/remotes.go b/go/libraries/doltcore/env/actions/remotes.go index 9b4c1f537d..142497c379 100644 --- a/go/libraries/doltcore/env/actions/remotes.go +++ b/go/libraries/doltcore/env/actions/remotes.go @@ -20,6 +20,8 @@ import ( "fmt" "sync" + "github.com/dolthub/dolt/go/cmd/dolt/cli" + eventsapi "github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1" "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" "github.com/dolthub/dolt/go/libraries/doltcore/env" @@ -258,7 +260,7 @@ func FetchCommit(ctx context.Context, tempTablesDir string, srcDB, destDB *doltd return destDB.PullChunks(ctx, tempTablesDir, srcDB, stRef, progChan, pullerEventCh) } -// FetchCommit takes a fetches a commit tag and all underlying data from a remote source database to the local destination database. +// FetchTag takes a fetches a commit tag and all underlying data from a remote source database to the local destination database. func FetchTag(ctx context.Context, tempTableDir string, srcDB, destDB *doltdb.DoltDB, srcDBTag *doltdb.Tag, progChan chan datas.PullProgress, pullerEventCh chan datas.PullerEvent) error { stRef, err := srcDBTag.GetStRef() @@ -274,7 +276,7 @@ func Clone(ctx context.Context, srcDB, destDB *doltdb.DoltDB, eventCh chan<- dat return srcDB.Clone(ctx, destDB, eventCh) } -// fetchFollowTags fetches all tags from the source DB whose commits have already +// FetchFollowTags fetches all tags from the source DB whose commits have already // been fetched into the destination DB. // todo: potentially too expensive to iterate over all srcDB tags func FetchFollowTags(ctx context.Context, tempTableDir string, srcDB, destDB *doltdb.DoltDB, progStarter ProgStarter, progStopper ProgStopper) error { @@ -313,6 +315,11 @@ func FetchFollowTags(ctx context.Context, tempTableDir string, srcDB, destDB *do wg, progChan, pullerEventCh := progStarter(newCtx) err = FetchTag(ctx, tempTableDir, srcDB, destDB, tag, progChan, pullerEventCh) progStopper(cancelFunc, wg, progChan, pullerEventCh) + if err == nil { + cli.Println() + } else if err == datas.ErrDBUpToDate { + err = nil + } if err != nil { return true, err @@ -352,6 +359,11 @@ func FetchRemoteBranch(ctx context.Context, tempTablesDir string, rem env.Remote wg, progChan, pullerEventCh := progStarter(newCtx) err = FetchCommit(ctx, tempTablesDir, srcDB, destDB, srcDBCommit, progChan, pullerEventCh) progStopper(cancelFunc, wg, progChan, pullerEventCh) + if err == nil { + cli.Println() + } else if err == datas.ErrDBUpToDate { + err = nil + } if err != nil { return nil, err diff --git a/integration-tests/bats/remotes.bats b/integration-tests/bats/remotes.bats index 675164b4ac..7620d0c61f 100644 --- a/integration-tests/bats/remotes.bats +++ b/integration-tests/bats/remotes.bats @@ -429,6 +429,93 @@ SQL [[ "$output" =~ "remotes/test-remote/poop" ]] || false } +@test "remotes: fetch output" { + # create main remote branch + dolt remote add origin http://localhost:50051/test-org/test-repo + dolt sql -q 'create table test (id int primary key);' + dolt add . + dolt commit -m 'create test table.' + dolt push origin main:main + + # create remote branch "branch1" + dolt checkout -b branch1 + dolt sql -q 'insert into test (id) values (1), (2), (3);' + dolt add . + dolt commit -m 'add some values to branch 1.' + dolt push --set-upstream origin branch1 + + # create remote branch "branch2" + dolt checkout -b branch2 + dolt sql -q 'insert into test (id) values (4), (5), (6);' + dolt add . + dolt commit -m 'add some values to branch 2.' + dolt push --set-upstream origin branch2 + + # create first clone + cd dolt-repo-clones + dolt clone http://localhost:50051/test-org/test-repo + cd test-repo + dolt status + run dolt status + [ "$status" -eq 0 ] + [[ "$output" =~ "On branch main" ]] || false + [[ "$output" =~ "nothing to commit, working tree clean" ]] || false + + cd ../.. + + # create second clone + cd "dolt-repo-clones" + dolt clone http://localhost:50051/test-org/test-repo test-repo2 + cd test-repo2 + dolt status + run dolt status + [ "$status" -eq 0 ] + [[ "$output" =~ "On branch main" ]] || false + [[ "$output" =~ "nothing to commit, working tree clean" ]] || false + + # CHANGE 1: add more data to branch1 + dolt checkout -b branch1 remotes/origin/branch1 + dolt sql -q 'insert into test (id) values (100), (101), (102);' + dolt add . + dolt commit -m 'add more values to branch 1.' + dolt push --set-upstream origin branch1 + + # CHANGE 2: add more data to branch2 + dolt checkout -b branch2 remotes/origin/branch2 + dolt sql -q 'insert into test (id) values (103), (104), (105);' + dolt add . + dolt commit -m 'add more values to branch 2.' + dolt push --set-upstream origin branch2 + + # CHANGE 3: create remote branch "branch3" + dolt checkout -b branch3 + dolt sql -q 'insert into test (id) values (7), (8), (9);' + dolt add . + dolt commit -m 'add some values to branch 3.' + dolt push --set-upstream origin branch3 + + # CHANGE 4: create remote branch "branch4" + dolt checkout -b branch4 + dolt sql -q 'insert into test (id) values (10), (11), (12);' + dolt add . + dolt commit -m 'add some values to branch 4.' + dolt push --set-upstream origin branch4 + + cd .. + cd test-repo + run dolt fetch + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 4 ] + [ "${lines[0]}" != "" ] + [ "${lines[1]}" != "" ] + [ "${lines[2]}" != "" ] + [ "${lines[3]}" != "" ] + + run dolt fetch + [ "$status" -eq 0 ] + [ "$output" = "" ] +} + @test "remotes: dolt fetch with docs" { # Initial commit of docs on remote echo "initial-license" > LICENSE.md @@ -457,7 +544,7 @@ SQL run cat README.md [ "$status" -eq 0 ] [[ "$output" =~ "initial-readme" ]] || false - # Change the docs + # Change the docs echo "dolt-repo-clones-license" > LICENSE.md echo "dolt-repo-clones-readme" > README.md dolt add .