makes -f default behavior for dolt fetch

This commit is contained in:
Stephanie You
2023-02-03 16:07:19 -08:00
parent 43907f3b0b
commit fd0e4d6faa
3 changed files with 25 additions and 14 deletions

View File

@@ -228,7 +228,6 @@ func CreateCherryPickArgParser() *argparser.ArgParser {
func CreateFetchArgParser() *argparser.ArgParser {
ap := argparser.NewArgParser()
ap.SupportsFlag(ForceFlag, "f", "Update refs to remote branches with the current state of the remote, overwriting any conflicting history.")
return ap
}

View File

@@ -77,22 +77,14 @@ func (cmd FetchCmd) Exec(ctx context.Context, commandStr string, args []string,
if err != nil {
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
}
updateMode := ref.UpdateMode{Force: apr.Contains(cli.ForceFlag)}
srcDB, err := r.GetRemoteDBWithoutCaching(ctx, dEnv.DbData().Ddb.ValueReadWriter().Format(), dEnv)
if err != nil {
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
}
err = actions.FetchRefSpecs(ctx, dEnv.DbData(), srcDB, refSpecs, r, updateMode, buildProgStarter(downloadLanguage), stopProgFuncs)
switch err {
case doltdb.ErrUpToDate:
return HandleVErrAndExitCode(nil, usage)
case actions.ErrCantFF:
verr := errhand.BuildDError("error: fetch failed, can't fast forward remote tracking ref").AddCause(err).Build()
return HandleVErrAndExitCode(verr, usage)
}
if err != nil {
err = actions.FetchRefSpecs(ctx, dEnv.DbData(), srcDB, refSpecs, r, ref.UpdateMode{Force: true}, buildProgStarter(downloadLanguage), stopProgFuncs)
if err != nil && err != doltdb.ErrUpToDate {
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
}
return HandleVErrAndExitCode(nil, usage)

View File

@@ -1217,6 +1217,28 @@ SQL
[ "$status" -eq 0 ]
}
@test "remotes: fetch after force push" {
mkdir remote clone1
cd clone1
dolt init
dolt sql -q "create table t (pk int primary key);"
dolt commit -Am "commit1"
dolt remote add origin file://../remote
dolt push origin main
cd ..
dolt clone file://./remote clone2
cd clone1
dolt commit --amend -m "commit1 edited"
dolt push origin main -f
cd ../clone2
run dolt fetch
[ "$status" -eq 0 ]
}
@test "remotes: force fetch from main" {
dolt remote add test-remote http://localhost:50051/test-org/test-repo
dolt push --set-upstream test-remote main
@@ -1256,11 +1278,9 @@ SQL
dolt fetch
dolt push -f origin main
cd ../../
run dolt fetch test-remote
[ "$status" -ne 0 ]
run dolt pull
[ "$status" -ne 0 ]
run dolt fetch -f test-remote
run dolt fetch test-remote
[ "$status" -eq 0 ]
run dolt pull --no-edit
[ "$status" -eq 0 ]