From 5072a32382fb65fa7295811575d0f5c09cbe0dc3 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Mon, 29 Oct 2007 09:41:18 +0100 Subject: Teach git-pull about --[no-]ff, --no-squash and --commit These options are supported by git-merge, but git-pull didn't know about them. Signed-off-by: Lars Hjemli Signed-off-by: Junio C Hamano --- git-pull.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'git-pull.sh') diff --git a/git-pull.sh b/git-pull.sh index 74bfc16744..75ec011969 100755 --- a/git-pull.sh +++ b/git-pull.sh @@ -4,7 +4,7 @@ # # Fetch one or more remote refs and merge it/them into the current HEAD. -USAGE='[-n | --no-summary] [--no-commit] [-s strategy]... [] ...' +USAGE='[-n | --no-summary] [--[no-]commit] [--[no-]squash] [--[no-]ff] [-s strategy]... [] ...' LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEAD.' SUBDIRECTORY_OK=Yes . git-sh-setup @@ -15,7 +15,7 @@ cd_to_toplevel test -z "$(git ls-files -u)" || die "You are in the middle of a conflicted merge." -strategy_args= no_summary= no_commit= squash= +strategy_args= no_summary= no_commit= squash= no_ff= while : do case "$1" in @@ -27,8 +27,16 @@ do ;; --no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit) no_commit=--no-commit ;; + --c|--co|--com|--comm|--commi|--commit) + no_commit=--commit ;; --sq|--squ|--squa|--squas|--squash) squash=--squash ;; + --no-sq|--no-squ|--no-squa|--no-squas|--no-squash) + squash=--no-squash ;; + --ff) + no_ff=--ff ;; + --no-ff) + no_ff=--no-ff ;; -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\ --strateg=*|--strategy=*|\ -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy) @@ -133,5 +141,5 @@ then fi merge_name=$(git fmt-merge-msg <"$GIT_DIR/FETCH_HEAD") || exit -exec git-merge $no_summary $no_commit $squash $strategy_args \ +exec git-merge $no_summary $no_commit $squash $no_ff $strategy_args \ "$merge_name" HEAD $merge_head -- cgit v1.2.3 From 8f321a39257a06db014a3b6ae5dce839821cdb16 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 6 Nov 2007 01:50:02 -0800 Subject: scripts: Add placeholders for OPTIONS_SPEC --text follows this line-- These commands currently lack OPTIONS_SPEC; allow people to easily list with "git grep 'OPTIONS_SPEC=$'" what they can help improving. Signed-off-by: Junio C Hamano --- git-pull.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'git-pull.sh') diff --git a/git-pull.sh b/git-pull.sh index 75ec011969..30fdc57310 100755 --- a/git-pull.sh +++ b/git-pull.sh @@ -7,6 +7,7 @@ USAGE='[-n | --no-summary] [--[no-]commit] [--[no-]squash] [--[no-]ff] [-s strategy]... [] ...' LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEAD.' SUBDIRECTORY_OK=Yes +OPTIONS_SPEC= . git-sh-setup set_reflog_action "pull $*" require_work_tree -- cgit v1.2.3 From cd67e4d46b122b161f2ad7d943e4ae7aa8df6cf5 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 28 Nov 2007 13:11:07 +0000 Subject: Teach 'git pull' about --rebase When calling 'git pull' with the '--rebase' option, it performs a fetch + rebase instead of a fetch + merge. This behavior is more desirable than fetch + pull when a topic branch is ready to be submitted and needs to be update. fetch + rebase might also be considered a better workflow with shared repositories in any case, or for contributors to a centrally managed repository, such as WINE's. As a convenience, you can set the default behavior for a branch by defining the config variable branch..rebase, which is interpreted as a bool. This setting can be overridden on the command line by --rebase and --no-rebase. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-pull.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'git-pull.sh') diff --git a/git-pull.sh b/git-pull.sh index 30fdc57310..698e82b116 100755 --- a/git-pull.sh +++ b/git-pull.sh @@ -17,6 +17,9 @@ test -z "$(git ls-files -u)" || die "You are in the middle of a conflicted merge." strategy_args= no_summary= no_commit= squash= no_ff= +curr_branch=$(git symbolic-ref -q HEAD) +curr_branch_short=$(echo "$curr_branch" | sed "s|refs/heads/||") +rebase=$(git config --bool branch.$curr_branch_short.rebase) while : do case "$1" in @@ -52,6 +55,12 @@ do esac strategy_args="${strategy_args}-s $strategy " ;; + -r|--r|--re|--reb|--reba|--rebas|--rebase) + rebase=true + ;; + --no-r|--no-re|--no-reb|--no-reba|--no-rebas|--no-rebase) + rebase=false + ;; -h|--h|--he|--hel|--help) usage ;; @@ -95,7 +104,6 @@ merge_head=$(sed -e '/ not-for-merge /d' \ case "$merge_head" in '') - curr_branch=$(git symbolic-ref -q HEAD) case $? in 0) ;; 1) echo >&2 "You are not currently on a branch; you must explicitly" @@ -142,5 +150,6 @@ then fi merge_name=$(git fmt-merge-msg <"$GIT_DIR/FETCH_HEAD") || exit +test true = "$rebase" && exec git-rebase $merge_head exec git-merge $no_summary $no_commit $squash $no_ff $strategy_args \ "$merge_name" HEAD $merge_head -- cgit v1.2.3 From 441ed4131b2d735fea08e4f6277c12b13acebd53 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 28 Dec 2007 13:58:43 -0800 Subject: "git pull --tags": error out with a better message. When "git pull --tags" is run without any other arguments, the standard error message "You told me to fetch and merge stuff but there is nothing to merge! You might want to fix your config" is given. While the error may be technically correct, fixing the config would not help, as "git pull --tags" itself tells "git fetch" not to use the configured refspecs. This commit makes "git pull --tags" to issue a different error message to avoid confusion. This is merely an interim solution. In the longer term, it would be a better approach to change the semantics of --tags option to make "git fetch" and "git pull" to: (1) behave as if no --tags was given (so an explicit refspec on the command line overrides configured ones, or no explicit refspecs on the command line takes configured ones); but (2) no auto-following of tags is made even when using configured refspecs; and (3) fetch all tags as not-for-merge entries". Then we would not need to have this separate error message, as the ordinary merge will happen even with the --tags option. Signed-off-by: Junio C Hamano --- git-pull.sh | 66 +++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 26 deletions(-) (limited to 'git-pull.sh') diff --git a/git-pull.sh b/git-pull.sh index 698e82b116..fa97b0f356 100755 --- a/git-pull.sh +++ b/git-pull.sh @@ -72,6 +72,40 @@ do shift done +error_on_no_merge_candidates () { + exec >&2 + for opt + do + case "$opt" in + -t|--t|--ta|--tag|--tags) + echo "Fetching tags only, you probably meant:" + echo " git fetch --tags" + exit 1 + esac + done + + curr_branch=${curr_branch#refs/heads/} + + echo "You asked me to pull without telling me which branch you" + echo "want to merge with, and 'branch.${curr_branch}.merge' in" + echo "your configuration file does not tell me either. Please" + echo "name which branch you want to merge on the command line and" + echo "try again (e.g. 'git pull ')." + echo "See git-pull(1) for details on the refspec." + echo + echo "If you often merge with the same branch, you may want to" + echo "configure the following variables in your configuration" + echo "file:" + echo + echo " branch.${curr_branch}.remote = " + echo " branch.${curr_branch}.merge = " + echo " remote..url = " + echo " remote..fetch = " + echo + echo "See git-config(1) for details." + exit 1 +} + orig_head=$(git rev-parse --verify HEAD 2>/dev/null) git-fetch --update-head-ok "$@" || exit 1 @@ -105,33 +139,13 @@ merge_head=$(sed -e '/ not-for-merge /d' \ case "$merge_head" in '') case $? in - 0) ;; - 1) echo >&2 "You are not currently on a branch; you must explicitly" - echo >&2 "specify which branch you wish to merge:" - echo >&2 " git pull " - exit 1;; - *) exit $?;; + 0) error_on_no_merge_candidates "$@";; + 1) echo >&2 "You are not currently on a branch; you must explicitly" + echo >&2 "specify which branch you wish to merge:" + echo >&2 " git pull " + exit 1;; + *) exit $?;; esac - curr_branch=${curr_branch#refs/heads/} - - echo >&2 "You asked me to pull without telling me which branch you" - echo >&2 "want to merge with, and 'branch.${curr_branch}.merge' in" - echo >&2 "your configuration file does not tell me either. Please" - echo >&2 "name which branch you want to merge on the command line and" - echo >&2 "try again (e.g. 'git pull ')." - echo >&2 "See git-pull(1) for details on the refspec." - echo >&2 - echo >&2 "If you often merge with the same branch, you may want to" - echo >&2 "configure the following variables in your configuration" - echo >&2 "file:" - echo >&2 - echo >&2 " branch.${curr_branch}.remote = " - echo >&2 " branch.${curr_branch}.merge = " - echo >&2 " remote..url = " - echo >&2 " remote..fetch = " - echo >&2 - echo >&2 "See git-config(1) for details." - exit 1 ;; ?*' '?*) if test -z "$orig_head" -- cgit v1.2.3 From c85c79279df2c8a583d95449d1029baba41f8660 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 26 Jan 2008 18:04:37 +0000 Subject: pull --rebase: be cleverer with rebased upstream branches When the upstream branch is tracked, we can detect if that branch was rebased since it was last fetched. Teach git to use that information to rebase from the old remote head onto the new remote head. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- git-pull.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'git-pull.sh') diff --git a/git-pull.sh b/git-pull.sh index fa97b0f356..46da0f4ca2 100755 --- a/git-pull.sh +++ b/git-pull.sh @@ -106,6 +106,15 @@ error_on_no_merge_candidates () { exit 1 } +test true = "$rebase" && { + . git-parse-remote && + origin="$1" + test -z "$origin" && origin=$(get_default_remote) + reflist="$(get_remote_refs_for_fetch "$@" 2>/dev/null | + sed "s|refs/heads/\(.*\):|\1|")" && + oldremoteref="$(git rev-parse --verify \ + "refs/remotes/$origin/$reflist" 2>/dev/null)" +} orig_head=$(git rev-parse --verify HEAD 2>/dev/null) git-fetch --update-head-ok "$@" || exit 1 @@ -164,6 +173,7 @@ then fi merge_name=$(git fmt-merge-msg <"$GIT_DIR/FETCH_HEAD") || exit -test true = "$rebase" && exec git-rebase $merge_head +test true = "$rebase" && + exec git-rebase --onto $merge_head ${oldremoteref:-$merge_head} exec git-merge $no_summary $no_commit $squash $no_ff $strategy_args \ "$merge_name" HEAD $merge_head -- cgit v1.2.3