Merge branch 'pt/pull-optparse'
"git pull" has become more aware of the options meant for underlying "git fetch" and then learned to use parse-options parser. * pt/pull-optparse: pull: use git-rev-parse --parseopt for option parsing pull: handle git-fetch's options as well
This commit is contained in:
commit
a1eaf8655d
@ -74,9 +74,6 @@ pulling or stash them away with linkgit:git-stash[1].
|
||||
OPTIONS
|
||||
-------
|
||||
|
||||
Options meant for 'git pull' itself and the underlying 'git merge'
|
||||
must be given before the options meant for 'git fetch'.
|
||||
|
||||
-q::
|
||||
--quiet::
|
||||
This is passed to both underlying git-fetch to squelch reporting of
|
||||
|
128
git-pull.sh
128
git-pull.sh
@ -4,13 +4,53 @@
|
||||
#
|
||||
# Fetch one or more remote refs and merge it/them into the current HEAD.
|
||||
|
||||
USAGE='[-n | --no-stat] [--[no-]commit] [--[no-]squash] [--[no-]ff|--ff-only] [--[no-]rebase|--rebase=preserve] [-s strategy]... [<fetch-options>] <repo> <head>...'
|
||||
LONG_USAGE='Fetch one or more remote refs and integrate it/them with the current HEAD.'
|
||||
SUBDIRECTORY_OK=Yes
|
||||
OPTIONS_SPEC=
|
||||
OPTIONS_KEEPDASHDASH=
|
||||
OPTIONS_STUCKLONG=Yes
|
||||
OPTIONS_SPEC="\
|
||||
git pull [options] [<repository> [<refspec>...]]
|
||||
|
||||
Fetch one or more remote refs and integrate it/them with the current HEAD.
|
||||
--
|
||||
v,verbose be more verbose
|
||||
q,quiet be more quiet
|
||||
progress force progress reporting
|
||||
|
||||
Options related to merging
|
||||
r,rebase?false|true|preserve incorporate changes by rebasing rather than merging
|
||||
n! do not show a diffstat at the end of the merge
|
||||
stat show a diffstat at the end of the merge
|
||||
summary (synonym to --stat)
|
||||
log?n add (at most <n>) entries from shortlog to merge commit message
|
||||
squash create a single commit instead of doing a merge
|
||||
commit perform a commit if the merge succeeds (default)
|
||||
e,edit edit message before committing
|
||||
ff allow fast-forward
|
||||
ff-only! abort if fast-forward is not possible
|
||||
verify-signatures verify that the named commit has a valid GPG signature
|
||||
s,strategy=strategy merge strategy to use
|
||||
X,strategy-option=option option for selected merge strategy
|
||||
S,gpg-sign?key-id GPG sign commit
|
||||
|
||||
Options related to fetching
|
||||
all fetch from all remotes
|
||||
a,append append to .git/FETCH_HEAD instead of overwriting
|
||||
upload-pack=path path to upload pack on remote end
|
||||
f,force force overwrite of local branch
|
||||
t,tags fetch all tags and associated objects
|
||||
p,prune prune remote-tracking branches no longer on remote
|
||||
recurse-submodules?on-demand control recursive fetching of submodules
|
||||
dry-run dry run
|
||||
k,keep keep downloaded pack
|
||||
depth=depth deepen history of shallow clone
|
||||
unshallow convert to a complete repository
|
||||
update-shallow accept refs that update .git/shallow
|
||||
refmap=refmap specify fetch refmap
|
||||
"
|
||||
test $# -gt 0 && args="$*"
|
||||
. git-sh-setup
|
||||
. git-sh-i18n
|
||||
set_reflog_action "pull${1+ $*}"
|
||||
set_reflog_action "pull${args+ $args}"
|
||||
require_work_tree_exists
|
||||
cd_to_toplevel
|
||||
|
||||
@ -44,7 +84,8 @@ bool_or_string_config () {
|
||||
|
||||
strategy_args= diffstat= no_commit= squash= no_ff= ff_only=
|
||||
log_arg= verbosity= progress= recurse_submodules= verify_signatures=
|
||||
merge_args= edit= rebase_args=
|
||||
merge_args= edit= rebase_args= all= append= upload_pack= force= tags= prune=
|
||||
keep= depth= unshallow= update_shallow= refmap=
|
||||
curr_branch=$(git symbolic-ref -q HEAD)
|
||||
curr_branch_short="${curr_branch#refs/heads/}"
|
||||
rebase=$(bool_or_string_config branch.$curr_branch_short.rebase)
|
||||
@ -86,17 +127,17 @@ do
|
||||
diffstat=--stat ;;
|
||||
--log|--log=*|--no-log)
|
||||
log_arg="$1" ;;
|
||||
--no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
|
||||
--no-commit)
|
||||
no_commit=--no-commit ;;
|
||||
--c|--co|--com|--comm|--commi|--commit)
|
||||
--commit)
|
||||
no_commit=--commit ;;
|
||||
-e|--edit)
|
||||
edit=--edit ;;
|
||||
--no-edit)
|
||||
edit=--no-edit ;;
|
||||
--sq|--squ|--squa|--squas|--squash)
|
||||
--squash)
|
||||
squash=--squash ;;
|
||||
--no-sq|--no-squ|--no-squa|--no-squas|--no-squash)
|
||||
--no-squash)
|
||||
squash=--no-squash ;;
|
||||
--ff)
|
||||
no_ff=--ff ;;
|
||||
@ -104,39 +145,19 @@ do
|
||||
no_ff=--no-ff ;;
|
||||
--ff-only)
|
||||
ff_only=--ff-only ;;
|
||||
-s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
|
||||
--strateg=*|--strategy=*|\
|
||||
-s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
|
||||
case "$#,$1" in
|
||||
*,*=*)
|
||||
strategy=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;;
|
||||
1,*)
|
||||
usage ;;
|
||||
*)
|
||||
strategy="$2"
|
||||
shift ;;
|
||||
esac
|
||||
strategy_args="${strategy_args}-s $strategy "
|
||||
-s*|--strategy=*)
|
||||
strategy_args="$strategy_args $1"
|
||||
;;
|
||||
-X*)
|
||||
case "$#,$1" in
|
||||
1,-X)
|
||||
usage ;;
|
||||
*,-X)
|
||||
xx="-X $(git rev-parse --sq-quote "$2")"
|
||||
shift ;;
|
||||
*,*)
|
||||
xx=$(git rev-parse --sq-quote "$1") ;;
|
||||
esac
|
||||
merge_args="$merge_args$xx "
|
||||
-X*|--strategy-option=*)
|
||||
merge_args="$merge_args $(git rev-parse --sq-quote "$1")"
|
||||
;;
|
||||
-r=*|--r=*|--re=*|--reb=*|--reba=*|--rebas=*|--rebase=*)
|
||||
-r*|--rebase=*)
|
||||
rebase="${1#*=}"
|
||||
;;
|
||||
-r|--r|--re|--reb|--reba|--rebas|--rebase)
|
||||
--rebase)
|
||||
rebase=true
|
||||
;;
|
||||
--no-r|--no-re|--no-reb|--no-reba|--no-rebas|--no-rebase)
|
||||
--no-rebase)
|
||||
rebase=false
|
||||
;;
|
||||
--recurse-submodules)
|
||||
@ -163,16 +184,41 @@ do
|
||||
-S*)
|
||||
gpg_sign_args=$(git rev-parse --sq-quote "$1")
|
||||
;;
|
||||
--d|--dr|--dry|--dry-|--dry-r|--dry-ru|--dry-run)
|
||||
--dry-run)
|
||||
dry_run=--dry-run
|
||||
;;
|
||||
--all|--no-all)
|
||||
all=$1 ;;
|
||||
-a|--append|--no-append)
|
||||
append=$1 ;;
|
||||
--upload-pack=*|--no-upload-pack)
|
||||
upload_pack=$1 ;;
|
||||
-f|--force|--no-force)
|
||||
force="$force $1" ;;
|
||||
-t|--tags|--no-tags)
|
||||
tags=$1 ;;
|
||||
-p|--prune|--no-prune)
|
||||
prune=$1 ;;
|
||||
-k|--keep|--no-keep)
|
||||
keep=$1 ;;
|
||||
--depth=*|--no-depth)
|
||||
depth=$1 ;;
|
||||
--unshallow|--no-unshallow)
|
||||
unshallow=$1 ;;
|
||||
--update-shallow|--no-update-shallow)
|
||||
update_shallow=$1 ;;
|
||||
--refmap=*|--no-refmap)
|
||||
refmap=$1 ;;
|
||||
-h|--help-all)
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
# Pass thru anything that may be meant for fetch.
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
@ -248,7 +294,9 @@ test true = "$rebase" && {
|
||||
oldremoteref=$(git merge-base --fork-point "$remoteref" $curr_branch 2>/dev/null)
|
||||
}
|
||||
orig_head=$(git rev-parse -q --verify HEAD)
|
||||
git fetch $verbosity $progress $dry_run $recurse_submodules --update-head-ok "$@" || exit 1
|
||||
git fetch $verbosity $progress $dry_run $recurse_submodules $all $append \
|
||||
$upload_pack $force $tags $prune $keep $depth $unshallow $update_shallow \
|
||||
$refmap --update-head-ok "$@" || exit 1
|
||||
test -z "$dry_run" || exit 0
|
||||
|
||||
curr_head=$(git rev-parse -q --verify HEAD)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user