added pull command tests

This commit is contained in:
Neil Macneale IV
2025-12-18 20:33:30 +00:00
parent 09edc870e9
commit 5215ed2f36
3 changed files with 84 additions and 0 deletions

View File

@@ -91,6 +91,14 @@ func (cmd PullCmd) Exec(ctx context.Context, commandStr string, args []string, d
verr := errhand.VerboseErrorFromError(errors.New(fmt.Sprintf(ErrConflictingFlags, cli.SquashParam, cli.NoFFParam)))
return HandleVErrAndExitCode(verr, usage)
}
if apr.ContainsAll(cli.FFOnlyParam, cli.NoFFParam) {
verr := errhand.VerboseErrorFromError(errors.New(fmt.Sprintf(ErrConflictingFlags, cli.FFOnlyParam, cli.NoFFParam)))
return HandleVErrAndExitCode(verr, usage)
}
if apr.ContainsAll(cli.FFOnlyParam, cli.SquashParam) {
verr := errhand.VerboseErrorFromError(errors.New(fmt.Sprintf(ErrConflictingFlags, cli.FFOnlyParam, cli.SquashParam)))
return HandleVErrAndExitCode(verr, usage)
}
// This command may create a commit, so we need user identity
if !cli.CheckUserNameAndEmail(cliCtx.Config()) {
bdr := errhand.BuildDError("Could not determine name and/or email.")
@@ -253,6 +261,9 @@ func constructInterpolatedDoltPullQuery(apr *argparser.ArgParseResults) (string,
if apr.Contains(cli.NoFFParam) {
args = append(args, "'--no-ff'")
}
if apr.Contains(cli.FFOnlyParam) {
args = append(args, "'--ff-only'")
}
if apr.Contains(cli.ForceFlag) {
args = append(args, "'--force'")
}

View File

@@ -96,6 +96,14 @@ func doDoltPull(ctx *sql.Context, args []string) (int, int, string, error) {
return noConflictsOrViolations, threeWayMerge, "", actions.ErrInvalidPullArgs
}
// Validate conflicting flags
if apr.ContainsAll(cli.FFOnlyParam, cli.NoFFParam) {
return noConflictsOrViolations, threeWayMerge, "", fmt.Errorf("error: Flags '--%s' and '--%s' cannot be used together", cli.FFOnlyParam, cli.NoFFParam)
}
if apr.ContainsAll(cli.FFOnlyParam, cli.SquashParam) {
return noConflictsOrViolations, threeWayMerge, "", fmt.Errorf("error: Flags '--%s' and '--%s' cannot be used together", cli.FFOnlyParam, cli.SquashParam)
}
var remoteName, remoteRefName string
if apr.NArg() == 1 {
remoteName = apr.Arg(0)

View File

@@ -581,3 +581,68 @@ SQL
# Verify that the remote branch was deleted.
[[ ! "$output" =~ "origin/new-branch" ]] || false
}
@test "pull: --ff-only succeeds when fast-forward is possible" {
cd repo2
run dolt sql -q "show tables" -r csv
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 1 ] # Only header, no tables
run dolt pull --ff-only origin
[ "$status" -eq 0 ]
[[ "$output" =~ "Fast-forward" ]] || false
run dolt sql -q "show tables" -r csv
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 2 ]
[[ "$output" =~ "t1" ]] || false
}
@test "pull: --ff-only fails when fast-forward is not possible" {
cd repo2
# Make a local commit that diverges from remote
dolt sql -q "create table divergent (id int primary key);"
dolt commit -Am "local divergent commit"
run dolt pull --ff-only origin
[ "$status" -eq 1 ]
[[ "$output" =~ "fatal: Not possible to fast-forward, aborting" ]] || false
}
@test "pull: --ff-only conflicts with --no-ff" {
cd repo2
run dolt pull --ff-only --no-ff origin
[ "$status" -eq 1 ]
[[ "$output" =~ "Flags '--ff-only' and '--no-ff' cannot be used together" ]] || false
}
@test "pull: --ff-only conflicts with --squash" {
cd repo2
run dolt pull --ff-only --squash origin
[ "$status" -eq 1 ]
[[ "$output" =~ "Flags '--ff-only' and '--squash' cannot be used together" ]] || false
}
@test "pull: --ff-only with already up-to-date branch" {
cd repo2
# First pull normally to get up to date
dolt pull origin
# Now pull again with --ff-only - should succeed with "up-to-date" message
run dolt pull --ff-only origin
[ "$status" -eq 0 ]
[[ "$output" =~ "Everything up-to-date" ]] || false
}
@test "pull: --ff-only works with --no-commit" {
cd repo2
run dolt pull --ff-only --no-commit origin
[ "$status" -eq 0 ]
[[ "$output" =~ "Fast-forward" ]] || false
run dolt sql -q "show tables" -r csv
[ "$status" -eq 0 ]
[[ "$output" =~ "t1" ]] || false
}