#!/bin/sh # # Copyright (c) 2005 Junio C Hamano # # Fetch one or more remote refs and merge it/them into the current HEAD. setglobal SUBDIRECTORY_OK = 'Yes' setglobal OPTIONS_KEEPDASHDASH = '' setglobal OPTIONS_STUCKLONG = 'Yes' setglobal OPTIONS_SPEC = '"\ git pull [options] [ [...]] 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 ) 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 $Argc -gt 0 && setglobal args = "$ifsjoin(Argv)" source git-sh-setup source git-sh-i18n set_reflog_action "pull$(args+ $args)" require_work_tree_exists cd_to_toplevel proc die_conflict { git diff-index --cached --name-status -r --ignore-submodules HEAD -- if test $[git config --bool --get advice.resolveConflict || echo true] = "true" { die $[gettext "Pull is not possible because you have unmerged files. Please, fix them up in the work tree, and then use 'git add/rm ' as appropriate to mark resolution and make a commit.] } else { die $[gettext "Pull is not possible because you have unmerged files.] } } proc die_merge { if test $[git config --bool --get advice.resolveConflict || echo true] = "true" { die $[gettext "You have not concluded your merge (MERGE_HEAD exists). Please, commit your changes before merging.] } else { die $[gettext "You have not concluded your merge (MERGE_HEAD exists).] } } test -z $[git ls-files -u] || die_conflict test -f "$GIT_DIR/MERGE_HEAD" && die_merge proc bool_or_string_config { git config --bool $1 !2 >/dev/null || git config $1 } setglobal strategy_args = '', diffstat = '', no_commit = '', squash = '', no_ff = '', ff_only = '' setglobal log_arg = '', verbosity = '', progress = '', recurse_submodules = '', verify_signatures = '' setglobal merge_args = '', edit = '', rebase_args = '', all = '', append = '', upload_pack = '', force = '', tags = '', prune = '' setglobal keep = '', depth = '', unshallow = '', update_shallow = '', refmap = '' setglobal curr_branch = $[git symbolic-ref -q HEAD] setglobal curr_branch_short = $(curr_branch#refs/heads/) setglobal rebase = $[bool_or_string_config branch.$curr_branch_short.rebase] if test -z $rebase { setglobal rebase = $[bool_or_string_config pull.rebase] } # Setup default fast-forward options via `pull.ff` setglobal pull_ff = $[bool_or_string_config pull.ff] match $pull_ff { with true setglobal no_ff = '--ff' with false setglobal no_ff = '--no-ff' with only setglobal ff_only = '--ff-only' } setglobal dry_run = '' while : { match $1 { with -q|--quiet setglobal verbosity = ""$verbosity -q"" with -v|--verbose setglobal verbosity = ""$verbosity -v"" with --progress setglobal progress = '--progress' with --no-progress setglobal progress = '--no-progress' with -n|--no-stat|--no-summary setglobal diffstat = '--no-stat' with --stat|--summary setglobal diffstat = '--stat' with --log|--log=*|--no-log setglobal log_arg = $1 with --no-commit setglobal no_commit = '--no-commit' with --commit setglobal no_commit = '--commit' with -e|--edit setglobal edit = '--edit' with --no-edit setglobal edit = '--no-edit' with --squash setglobal squash = '--squash' with --no-squash setglobal squash = '--no-squash' with --ff setglobal no_ff = '--ff' with --no-ff setglobal no_ff = '--no-ff' with --ff-only setglobal ff_only = '--ff-only' with -s*|--strategy=* setglobal strategy_args = ""$strategy_args $1"" with -X*|--strategy-option=* setglobal merge_args = ""$merge_args $[git rev-parse --sq-quote $1]"" with -r*|--rebase=* setglobal rebase = $(1#*=) with --rebase setglobal rebase = 'true' with --no-rebase setglobal rebase = 'false' with --recurse-submodules setglobal recurse_submodules = '--recurse-submodules' with --recurse-submodules=* setglobal recurse_submodules = $1 with --no-recurse-submodules setglobal recurse_submodules = '--no-recurse-submodules' with --verify-signatures setglobal verify_signatures = '--verify-signatures' with --no-verify-signatures setglobal verify_signatures = '--no-verify-signatures' with --gpg-sign|-S setglobal gpg_sign_args = '-S' with --gpg-sign=* setglobal gpg_sign_args = $[git rev-parse --sq-quote "-S$(1#--gpg-sign=)] with -S* setglobal gpg_sign_args = $[git rev-parse --sq-quote $1] with --dry-run setglobal dry_run = '--dry-run' with --all|--no-all setglobal all = $1 with -a|--append|--no-append setglobal append = $1 with --upload-pack=*|--no-upload-pack setglobal upload_pack = $1 with -f|--force|--no-force setglobal force = ""$force $1"" with -t|--tags|--no-tags setglobal tags = $1 with -p|--prune|--no-prune setglobal prune = $1 with -k|--keep|--no-keep setglobal keep = $1 with --depth=*|--no-depth setglobal depth = $1 with --unshallow|--no-unshallow setglobal unshallow = $1 with --update-shallow|--no-update-shallow setglobal update_shallow = $1 with --refmap=*|--no-refmap setglobal refmap = $1 with -h|--help-all usage with -- shift break with * usage } shift } match $rebase { with preserve setglobal rebase = 'true' setglobal rebase_args = '--preserve-merges' with true|false|'' with * echo "Invalid value for --rebase, should be true, false, or preserve" usage exit 1 } proc error_on_no_merge_candidates { exec > !2 if test true = $rebase { setglobal op_type = 'rebase' setglobal op_prep = 'against' } else { setglobal op_type = 'merge' setglobal op_prep = 'with' } setglobal upstream = $[git config "branch.$curr_branch_short.merge] setglobal remote = $[git config "branch.$curr_branch_short.remote] if test $Argc -gt 1 { if test $rebase = true { printf "There is no candidate for rebasing against " } else { printf "There are no candidates for merging " } echo "among the refs that you just fetched." echo "Generally this means that you provided a wildcard refspec which had no" echo "matches on the remote end." } elif test $Argc -gt 0 && test $1 != $remote { echo "You asked to pull from the remote '$1', but did not specify" echo "a branch. Because this is not the default configured remote" echo "for your current branch, you must specify a branch on the command line." } elif test -z $curr_branch -o -z $upstream { source git-parse-remote error_on_missing_default_upstream "pull" $op_type $op_prep \ "git pull " } else { echo "Your configuration specifies to $op_type $op_prep the ref '$(upstream#refs/heads/)'" echo "from the remote, but no such ref was fetched." } exit 1 } test true = $rebase && do { if ! git rev-parse -q --verify HEAD >/dev/null { # On an unborn branch if test -f $[git rev-parse --git-path index] { die $[gettext "updating an unborn branch with changes added to the index] } } else { require_clean_work_tree "pull with rebase" "Please commit or stash them." } setglobal oldremoteref = '' && test -n $curr_branch && source git-parse-remote && setglobal remoteref = $[get_remote_merge_branch @Argv !2 >/dev/null] && setglobal oldremoteref = $[git merge-base --fork-point $remoteref $curr_branch !2 >/dev/null] } setglobal orig_head = $[git rev-parse -q --verify HEAD] git fetch $verbosity $progress $dry_run $recurse_submodules $all $append \ $(upload_pack:+"$upload_pack") $force $tags $prune $keep $depth $unshallow $update_shallow \ $refmap --update-head-ok @Argv || exit 1 test -z $dry_run || exit 0 setglobal curr_head = $[git rev-parse -q --verify HEAD] if test -n $orig_head && test $curr_head != $orig_head { # The fetch involved updating the current branch. # The working tree and the index file is still based on the # $orig_head commit, but we are merging into $curr_head. # First update the working tree to match $curr_head. eval_gettextln "Warning: fetch updated the current branch head. Warning: fast-forwarding your working tree from Warning: commit \$orig_head." > !2 git update-index -q --refresh git read-tree -u -m $orig_head $curr_head || die $[eval_gettext "Cannot fast-forward your working tree. After making sure that you saved anything precious from $ git diff \$orig_head output, run $ git reset --hard to recover.] } setglobal merge_head = $[sed -e '/ not-for-merge /d' \ -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \ tr '\012' ' ] match $merge_head { with '' error_on_no_merge_candidates @Argv with ?*' '?* if test -z $orig_head { die $[gettext "Cannot merge multiple branches into empty head] } if test true = $rebase { die $[gettext "Cannot rebase onto multiple branches] } } # Pulling into unborn branch: a shorthand for branching off # FETCH_HEAD, for lazy typers. if test -z $orig_head { # Two-way merge: we claim the index is based on an empty tree, # and try to fast-forward to HEAD. This ensures we will not # lose index/worktree changes that the user already made on # the unborn branch. setglobal empty_tree = '4b825dc642cb6eb9a060e54bf8d69288fbee4904' git read-tree -m -u $empty_tree $merge_head && git update-ref -m "initial pull" HEAD $merge_head $curr_head exit } if test true = $rebase { setglobal o = $[git show-branch --merge-base $curr_branch $merge_head $oldremoteref] if test $oldremoteref = $o { unset oldremoteref } } match $rebase { with true setglobal eval = ""git-rebase $diffstat $strategy_args $merge_args $rebase_args $verbosity"" setglobal eval = ""$eval $gpg_sign_args"" setglobal eval = ""$eval --onto $merge_head $(oldremoteref:-$merge_head)"" with * setglobal eval = ""git-merge $diffstat $no_commit $verify_signatures $edit $squash $no_ff $ff_only"" setglobal eval = ""$eval $log_arg $strategy_args $merge_args $verbosity $progress"" setglobal eval = ""$eval $gpg_sign_args"" setglobal eval = ""$eval FETCH_HEAD"" } eval "exec $eval"