pull: handle git-fetch's options as well
While parsing the command-line arguments, git-pull stops parsing at the first unrecognized option, assuming that any subsequent options are for git-fetch, and can thus be kept in the shell's positional parameters list, so that it can be passed to git-fetch via the expansion of "$@". However, certain functions in git-pull assume that the positional parameters do not contain any options: * error_on_no_merge_candidates() uses the number of positional parameters to determine which error message to print out, and will thus print the wrong message if git-fetch's options are passed in as well. * the call to get_remote_merge_branch() assumes that the positional parameters only contains the optional repo and refspecs, and will thus silently fail if git-fetch's options are passed in as well. * --dry-run is a valid git-fetch option, but if provided after any git-fetch options, it is not recognized by git-pull and thus git-pull will continue to run the merge or rebase. Fix these bugs by teaching git-pull to parse git-fetch's options as well. Add tests to prevent regressions. This removes the limitation where git-fetch's options have to come after git-merge's and git-rebase's options on the command line. Update the documentation to reflect this. Signed-off-by: Paul Tan <pyokagan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
@ -160,6 +160,18 @@ test_expect_success 'fail if no configuration for current branch' '
|
||||
test "$(cat file)" = file
|
||||
'
|
||||
|
||||
test_expect_success 'pull --all: fail if no configuration for current branch' '
|
||||
git remote add test_remote . &&
|
||||
test_when_finished "git remote remove test_remote" &&
|
||||
git checkout -b test copy^ &&
|
||||
test_when_finished "git checkout -f copy && git branch -D test" &&
|
||||
test_config branch.test.remote test_remote &&
|
||||
test "$(cat file)" = file &&
|
||||
test_must_fail git pull --all 2>err &&
|
||||
test_i18ngrep "There is no tracking information" err &&
|
||||
test "$(cat file)" = file
|
||||
'
|
||||
|
||||
test_expect_success 'fail if upstream branch does not exist' '
|
||||
git checkout -b test copy^ &&
|
||||
test_when_finished "git checkout -f copy && git branch -D test" &&
|
||||
@ -365,6 +377,14 @@ test_expect_success '--rebase with rebased upstream' '
|
||||
|
||||
'
|
||||
|
||||
test_expect_success '--rebase -f with rebased upstream' '
|
||||
test_when_finished "test_might_fail git rebase --abort" &&
|
||||
git reset --hard to-rebase-orig &&
|
||||
git pull --rebase -f me copy &&
|
||||
test "conflicting modification" = "$(cat file)" &&
|
||||
test file = "$(cat file2)"
|
||||
'
|
||||
|
||||
test_expect_success '--rebase with rebased default upstream' '
|
||||
|
||||
git update-ref refs/remotes/me/copy copy-orig &&
|
||||
|
@ -130,4 +130,18 @@ test_expect_success 'git pull --dry-run' '
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'git pull --all --dry-run' '
|
||||
test_when_finished "rm -rf cloneddry" &&
|
||||
git init clonedry &&
|
||||
(
|
||||
cd clonedry &&
|
||||
git remote add origin ../parent &&
|
||||
git pull --all --dry-run &&
|
||||
test_path_is_missing .git/FETCH_HEAD &&
|
||||
test_path_is_missing .git/refs/remotes/origin/master &&
|
||||
test_path_is_missing .git/index &&
|
||||
test_path_is_missing file
|
||||
)
|
||||
'
|
||||
|
||||
test_done
|
||||
|
Reference in New Issue
Block a user