From 5677882be721be5e2706a546d90804da8d8d0bd5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 22 Nov 2006 23:15:00 -0800 Subject: git-fetch: allow glob pattern in refspec This adds Andy's refspec glob. You can have a single line: Pull: refs/heads/*:refs/remotes/origin/* in your ".git/remotes/origin" and say "git fetch" to retrieve all refs under heads/ at the remote side to remotes/origin/ in the local repository. Signed-off-by: Junio C Hamano --- git-parse-remote.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'git-parse-remote.sh') diff --git a/git-parse-remote.sh b/git-parse-remote.sh index c325ef761e..e281b7c6eb 100755 --- a/git-parse-remote.sh +++ b/git-parse-remote.sh @@ -90,6 +90,39 @@ get_remote_default_refs_for_push () { esac } +# Called from canon_refs_list_for_fetch -d "$remote", which +# is called from get_remote_default_refs_for_fetch to grok +# refspecs that are retrieved from the configuration, but not +# from get_remote_refs_for_fetch when it deals with refspecs +# supplied on the command line. $ls_remote_result has the list +# of refs available at remote. +expand_refs_wildcard () { + for ref + do + # a non glob pattern is given back as-is. + expr "z$ref" : 'zrefs/.*/\*:refs/.*/\*$' >/dev/null || { + echo "$ref" + continue + } + from=`expr "z$ref" : 'z\(refs/.*/\)\*:refs/.*/\*$'` + to=`expr "z$ref" : 'zrefs/.*/\*:\(refs/.*/\)\*$'` + echo "$ls_remote_result" | + ( + IFS=' ' + while read sha1 name + do + mapped=${name#"$from"} + if test "z$name" != "z${name#'^{}'}" || + test "z$name" = "z$mapped" + then + continue + fi + echo "${name}:${to}${mapped}" + done + ) + done +} + # Subroutine to canonicalize remote:local notation. canon_refs_list_for_fetch () { # If called from get_remote_default_refs_for_fetch @@ -107,6 +140,8 @@ canon_refs_list_for_fetch () { merge_branches=$(git-repo-config \ --get-all "branch.${curr_branch}.merge") fi + set x $(expand_refs_wildcard "$@") + shift fi for ref do -- cgit v1.3 From d945d4be20d577868646f1b676b605cd9fdadf86 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 25 Nov 2006 01:10:10 -0800 Subject: git-fetch: allow forcing glob pattern in refspec Building on top of the earlier refspec glob pattern enhancement, this allows a glob pattern to say the updates should be forced by prefixing it with '+' as usual, like this: Pull: +refs/heads/*:refs/remotes/origin/* Signed-off-by: Junio C Hamano --- git-parse-remote.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'git-parse-remote.sh') diff --git a/git-parse-remote.sh b/git-parse-remote.sh index e281b7c6eb..19bc3857d1 100755 --- a/git-parse-remote.sh +++ b/git-parse-remote.sh @@ -99,13 +99,17 @@ get_remote_default_refs_for_push () { expand_refs_wildcard () { for ref do + lref=${ref#'+'} # a non glob pattern is given back as-is. - expr "z$ref" : 'zrefs/.*/\*:refs/.*/\*$' >/dev/null || { + expr "z$lref" : 'zrefs/.*/\*:refs/.*/\*$' >/dev/null || { echo "$ref" continue } - from=`expr "z$ref" : 'z\(refs/.*/\)\*:refs/.*/\*$'` - to=`expr "z$ref" : 'zrefs/.*/\*:\(refs/.*/\)\*$'` + + from=`expr "z$lref" : 'z\(refs/.*/\)\*:refs/.*/\*$'` + to=`expr "z$lref" : 'zrefs/.*/\*:\(refs/.*/\)\*$'` + local_force= + test "z$lref" = "z$ref" || local_force='+' echo "$ls_remote_result" | ( IFS=' ' @@ -117,7 +121,7 @@ expand_refs_wildcard () { then continue fi - echo "${name}:${to}${mapped}" + echo "${local_force}${name}:${to}${mapped}" done ) done -- cgit v1.3 From 4cd75359ad5d4c90ba6ae6d68ffb6d00e5092b8a Mon Sep 17 00:00:00 2001 From: Michael Loeffler Date: Mon, 4 Dec 2006 20:34:34 +0100 Subject: git-fetch: ignore dereferenced tags in expand_refs_wildcard There was a little bug in the brace expansion which should remove the ^{} from the tagname. It used ${name#'^{}'} instead of $(name%'^{}'}, the difference is that '#' will remove the given pattern only from the beginning of a string and '%' only from the end of a string. Signed-off-by: Michael Loeffler Signed-off-by: Junio C Hamano --- git-parse-remote.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git-parse-remote.sh') diff --git a/git-parse-remote.sh b/git-parse-remote.sh index 19bc3857d1..da064a53f6 100755 --- a/git-parse-remote.sh +++ b/git-parse-remote.sh @@ -116,7 +116,7 @@ expand_refs_wildcard () { while read sha1 name do mapped=${name#"$from"} - if test "z$name" != "z${name#'^{}'}" || + if test "z$name" != "z${name%'^{}'}" || test "z$name" = "z$mapped" then continue -- cgit v1.3 From 62b339a544b1fa5199de7571c460d770cb286e65 Mon Sep 17 00:00:00 2001 From: Josef Weidendorfer Date: Sat, 9 Dec 2006 02:28:26 +0100 Subject: Add branch.*.merge warning and documentation update This patch clarifies the meaning of the branch.*.merge option. Previously, if branch.*.merge was specified but did not match any ref, the message "No changes." was not really helpful regarding the misconfiguration. This patch adds a warning for this. Signed-off-by: Josef Weidendorfer Signed-off-by: Junio C Hamano --- Documentation/config.txt | 11 +++++++++-- git-parse-remote.sh | 11 +++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'git-parse-remote.sh') diff --git a/Documentation/config.txt b/Documentation/config.txt index 9090762819..21ec55797b 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -125,10 +125,17 @@ apply.whitespace:: branch..remote:: When in branch , it tells `git fetch` which remote to fetch. + If this option is not given, `git fetch` defaults to remote "origin". branch..merge:: - When in branch , it tells `git fetch` the default remote branch - to be merged. + When in branch , it tells `git fetch` the default refspec to + be marked for merging in FETCH_HEAD. The value has exactly to match + a remote part of one of the refspecs which are fetched from the remote + given by "branch..remote". + The merge information is used by `git pull` (which at first calls + `git fetch`) to lookup the default branch for merging. Without + this option, `git pull` defaults to merge the first refspec fetched. + Specify multiple values to get an octopus merge. pager.color:: A boolean to enable/disable colored output when the pager is in diff --git a/git-parse-remote.sh b/git-parse-remote.sh index da064a53f6..6ae534bf89 100755 --- a/git-parse-remote.sh +++ b/git-parse-remote.sh @@ -134,6 +134,8 @@ canon_refs_list_for_fetch () { # or the first one otherwise; add prefix . to the rest # to prevent the secondary branches to be merged by default. merge_branches= + found_mergeref= + curr_branch= if test "$1" = "-d" then shift ; remote="$1" ; shift @@ -171,6 +173,10 @@ canon_refs_list_for_fetch () { dot_prefix= && break done fi + if test -z $dot_prefix + then + found_mergeref=true + fi case "$remote" in '') remote=HEAD ;; refs/heads/* | refs/tags/* | refs/remotes/*) ;; @@ -191,6 +197,11 @@ canon_refs_list_for_fetch () { fi echo "${dot_prefix}${force}${remote}:${local}" done + if test -z "$found_mergeref" -a "$curr_branch" + then + echo >&2 "Warning: No merge candidate found because value of config option + \"branch.${curr_branch}.merge\" does not match any remote branch fetched." + fi } # Returns list of src: (no store), or src:dst (store) -- cgit v1.3 From a71fb0a1412c82405f078fb536797d3f5de68d53 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 16 Dec 2006 01:36:32 -0800 Subject: git-pull: refuse default merge without branch.*.merge Everybody hated the pull behaviour of merging the first branch listed on remotes/* file (or remote.*.fetch config) into the current branch. This finally corrects that UI wart by forbidding "git pull" without an explicit branch name on the command line or branch.$current.merge for the current branch. The matching change to git-clone was made to prepare the default branch.*.merge entry for the primary branch some time ago. Signed-off-by: Junio C Hamano --- git-parse-remote.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'git-parse-remote.sh') diff --git a/git-parse-remote.sh b/git-parse-remote.sh index 6ae534bf89..f27c3c231b 100755 --- a/git-parse-remote.sh +++ b/git-parse-remote.sh @@ -144,7 +144,8 @@ canon_refs_list_for_fetch () { curr_branch=$(git-symbolic-ref HEAD | \ sed -e 's|^refs/heads/||') merge_branches=$(git-repo-config \ - --get-all "branch.${curr_branch}.merge") + --get-all "branch.${curr_branch}.merge") || + merge_branches=.this.would.never.match.any.ref. fi set x $(expand_refs_wildcard "$@") shift -- cgit v1.3 From 0c7a97fafdaf7911183807019dbbb4d8c5079c4e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 18 Dec 2006 12:13:46 -0800 Subject: parse-remote::expand_refs_wildcard() Work around dash incompatibility by not using "${name%'^{}'}". Noticed by Jeff King; dash seems to mistake the closing brace inside the single quote as the terminating brace for parameter expansion. Signed-off-by: Junio C Hamano --- git-parse-remote.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'git-parse-remote.sh') diff --git a/git-parse-remote.sh b/git-parse-remote.sh index 6ae534bf89..bc881cc5f9 100755 --- a/git-parse-remote.sh +++ b/git-parse-remote.sh @@ -111,16 +111,14 @@ expand_refs_wildcard () { local_force= test "z$lref" = "z$ref" || local_force='+' echo "$ls_remote_result" | + sed -e '/\^{}$/d' | ( IFS=' ' while read sha1 name do + # ignore the ones that do not start with $from mapped=${name#"$from"} - if test "z$name" != "z${name%'^{}'}" || - test "z$name" = "z$mapped" - then - continue - fi + test "z$name" = "z$mapped" && continue echo "${local_force}${name}:${to}${mapped}" done ) -- cgit v1.3 From 4363dfbe3d2f3fe3a4bd0fa7e9b22a14532c6cdb Mon Sep 17 00:00:00 2001 From: Josef Weidendorfer Date: Tue, 19 Dec 2006 01:39:07 +0100 Subject: Move "no merge candidate" warning into git-pull The warning triggered even when running "git fetch" only when resulting .git/FETCH_HEAD only contained branches marked as 'not-for-merge'. Signed-off-by: Josef Weidendorfer Signed-off-by: Junio C Hamano --- git-parse-remote.sh | 10 ---------- git-pull.sh | 4 ++++ 2 files changed, 4 insertions(+), 10 deletions(-) (limited to 'git-parse-remote.sh') diff --git a/git-parse-remote.sh b/git-parse-remote.sh index 11c4aba244..ea7511e8a0 100755 --- a/git-parse-remote.sh +++ b/git-parse-remote.sh @@ -132,7 +132,6 @@ canon_refs_list_for_fetch () { # or the first one otherwise; add prefix . to the rest # to prevent the secondary branches to be merged by default. merge_branches= - found_mergeref= curr_branch= if test "$1" = "-d" then @@ -172,10 +171,6 @@ canon_refs_list_for_fetch () { dot_prefix= && break done fi - if test -z $dot_prefix - then - found_mergeref=true - fi case "$remote" in '') remote=HEAD ;; refs/heads/* | refs/tags/* | refs/remotes/*) ;; @@ -196,11 +191,6 @@ canon_refs_list_for_fetch () { fi echo "${dot_prefix}${force}${remote}:${local}" done - if test -z "$found_mergeref" -a "$curr_branch" - then - echo >&2 "Warning: No merge candidate found because value of config option - \"branch.${curr_branch}.merge\" does not match any remote branch fetched." - fi } # Returns list of src: (no store), or src:dst (store) diff --git a/git-pull.sh b/git-pull.sh index e23beb685d..1703091bbb 100755 --- a/git-pull.sh +++ b/git-pull.sh @@ -76,6 +76,10 @@ merge_head=$(sed -e '/ not-for-merge /d' \ case "$merge_head" in '') + curr_branch=$(git-symbolic-ref HEAD | \ + sed -e 's|^refs/heads/||') + echo >&2 "Warning: No merge candidate found because value of config option + \"branch.${curr_branch}.merge\" does not match any remote branch fetched." echo >&2 "No changes." exit 0 ;; -- cgit v1.3 From 9e11554917d391c18e043bc0b38ee0377e69568e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 21 Dec 2006 22:10:56 -0800 Subject: Revert "git-pull: refuse default merge without branch.*.merge" This reverts commit a71fb0a1412c82405f078fb536797d3f5de68d53. The logic to decide when to refuse to use the default "first set of refs fetched" for merge was utterly bogus. In a repository that happily worked correctly without any of the per-branch configuration crap did not have (and did not have to have) any branch..merge. With that broken commit, pulling from origin no longer would work. --- git-parse-remote.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'git-parse-remote.sh') diff --git a/git-parse-remote.sh b/git-parse-remote.sh index ea7511e8a0..871c08f097 100755 --- a/git-parse-remote.sh +++ b/git-parse-remote.sh @@ -141,8 +141,7 @@ canon_refs_list_for_fetch () { curr_branch=$(git-symbolic-ref HEAD | \ sed -e 's|^refs/heads/||') merge_branches=$(git-repo-config \ - --get-all "branch.${curr_branch}.merge") || - merge_branches=.this.would.never.match.any.ref. + --get-all "branch.${curr_branch}.merge") fi set x $(expand_refs_wildcard "$@") shift -- cgit v1.3 From d41cb273d313a21979b05dba57d0c6b565b28ba6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 21 Dec 2006 22:39:09 -0800 Subject: parse-remote: mark all refs not for merge only when fetching more than one An earlier commit a71fb0a1 implemented much requested safety valve to refuse "git pull" or "git pull origin" without explicit refspecs from using the first set of remote refs obtained by reading .git/remotes/origin file or branch.*.fetch configuration variables to create a merge. The argument was that while on a branch different from the default branch, it is often wrong to merge the default remote ref suitable for merging into the master. That is fine as a theory. But many repositories already in use by people in the real world do not have any of the per branch configuration crap. They did not need it, and they do not need it now. Merging with the first remote ref listed was just fine, because they had only one ref (e.g. 'master' from linux-2.6.git) anyway. So this changes the safety valve to be a lot looser. When "git fetch" gets only one remote branch, the irritating warning would not trigger anymore. I think we could also make the warning trigger when branch.*.merge is not specified for the current branch, but is for some other branch. That is for another commit. Signed-off-by: Junio C Hamano --- git-parse-remote.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'git-parse-remote.sh') diff --git a/git-parse-remote.sh b/git-parse-remote.sh index 871c08f097..f163821d03 100755 --- a/git-parse-remote.sh +++ b/git-parse-remote.sh @@ -136,6 +136,8 @@ canon_refs_list_for_fetch () { if test "$1" = "-d" then shift ; remote="$1" ; shift + set x $(expand_refs_wildcard "$@") + shift if test "$remote" = "$(get_default_remote)" then curr_branch=$(git-symbolic-ref HEAD | \ @@ -143,8 +145,13 @@ canon_refs_list_for_fetch () { merge_branches=$(git-repo-config \ --get-all "branch.${curr_branch}.merge") fi - set x $(expand_refs_wildcard "$@") - shift + # If we are fetching only one branch, then first branch + # is the only thing that makes sense to merge anyway, + # so there is no point refusing that traditional rule. + if test $# != 1 && test "z$merge_branches" = z + then + merge_branches=..this..would..never..match.. + fi fi for ref do -- cgit v1.3 From fb8696d9d82e78fe829fdd95ff9ff10fdfa52ef9 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 22 Dec 2006 15:25:21 -0800 Subject: default pull: forget about "newbie protection" for now. This will not be backward compatible no matter how you cut it. Shelve it for now until somebody comes up with a better way to determine when we can safely refuse to use the first set of branchse for merging without upsetting valid workflows. Signed-off-by: Junio C Hamano --- git-parse-remote.sh | 7 ------- 1 file changed, 7 deletions(-) (limited to 'git-parse-remote.sh') diff --git a/git-parse-remote.sh b/git-parse-remote.sh index f163821d03..b163d22ddb 100755 --- a/git-parse-remote.sh +++ b/git-parse-remote.sh @@ -145,13 +145,6 @@ canon_refs_list_for_fetch () { merge_branches=$(git-repo-config \ --get-all "branch.${curr_branch}.merge") fi - # If we are fetching only one branch, then first branch - # is the only thing that makes sense to merge anyway, - # so there is no point refusing that traditional rule. - if test $# != 1 && test "z$merge_branches" = z - then - merge_branches=..this..would..never..match.. - fi fi for ref do -- cgit v1.3 From ea560e6d64374ec1f6c163c276319a3da21a1345 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 22 Dec 2006 15:37:48 -0800 Subject: Do not support "partial URL shorthand" anymore. We used to support specifying the top part of remote URL in remotes and use that as a short-hand for the URL. $ cat .git/remotes/jgarzik URL: git://git.kernel.org/pub/scm/linux/kernel/git/jgarzik/ $ git pull jgarzik/misc-2.6 This is confusing when somebody attempts to do this: $ git pull origin/foo which is not syntactically correct (unless you have origin/foo.git repository) and should fail, but it resulted in a mysterious access to the 'foo' subdirectory of the origin repository. Which was what it was designed to do, but because this is an oddball "feature" I suspect nobody uses, let's remove it. Signed-off-by: Junio C Hamano --- git-parse-remote.sh | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) (limited to 'git-parse-remote.sh') diff --git a/git-parse-remote.sh b/git-parse-remote.sh index b163d22ddb..aaef861ada 100755 --- a/git-parse-remote.sh +++ b/git-parse-remote.sh @@ -7,18 +7,7 @@ GIT_DIR=$(git-rev-parse --git-dir 2>/dev/null) || :; get_data_source () { case "$1" in */*) - # Not so fast. This could be the partial URL shorthand... - token=$(expr "z$1" : 'z\([^/]*\)/') - remainder=$(expr "z$1" : 'z[^/]*/\(.*\)') - if test "$(git-repo-config --get "remote.$token.url")" - then - echo config-partial - elif test -f "$GIT_DIR/branches/$token" - then - echo branches-partial - else - echo '' - fi + echo '' ;; *) if test "$(git-repo-config --get "remote.$1.url")" @@ -40,12 +29,7 @@ get_remote_url () { data_source=$(get_data_source "$1") case "$data_source" in '') - echo "$1" ;; - config-partial) - token=$(expr "z$1" : 'z\([^/]*\)/') - remainder=$(expr "z$1" : 'z[^/]*/\(.*\)') - url=$(git-repo-config --get "remote.$token.url") - echo "$url/$remainder" + echo "$1" ;; config) git-repo-config --get "remote.$1.url" @@ -54,14 +38,10 @@ get_remote_url () { sed -ne '/^URL: */{ s///p q - }' "$GIT_DIR/remotes/$1" ;; + }' "$GIT_DIR/remotes/$1" + ;; branches) - sed -e 's/#.*//' "$GIT_DIR/branches/$1" ;; - branches-partial) - token=$(expr "z$1" : 'z\([^/]*\)/') - remainder=$(expr "z$1" : 'z[^/]*/\(.*\)') - url=$(sed -e 's/#.*//' "$GIT_DIR/branches/$token") - echo "$url/$remainder" + sed -e 's/#.*//' "$GIT_DIR/branches/$1" ;; *) die "internal error: get-remote-url $1" ;; @@ -77,7 +57,7 @@ get_default_remote () { get_remote_default_refs_for_push () { data_source=$(get_data_source "$1") case "$data_source" in - '' | config-partial | branches | branches-partial) + '' | branches) ;; # no default push mapping, just send matching refs. config) git-repo-config --get-all "remote.$1.push" ;; @@ -196,7 +176,7 @@ canon_refs_list_for_fetch () { get_remote_default_refs_for_fetch () { data_source=$(get_data_source "$1") case "$data_source" in - '' | config-partial | branches-partial) + '') echo "HEAD:" ;; config) canon_refs_list_for_fetch -d "$1" \ -- cgit v1.3 From 80c797764a6b6a373f0f1f47d7f56b0d950418a9 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 24 Dec 2006 01:59:53 -0800 Subject: Allow branch.*.merge to talk about remote tracking branches. People often get confused if the value of branch.*.merge should be the remote branch name they are fetching from, or the tracking branch they locally have. So this allows either. Signed-off-by: Junio C Hamano --- git-parse-remote.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'git-parse-remote.sh') diff --git a/git-parse-remote.sh b/git-parse-remote.sh index aaef861ada..144f170155 100755 --- a/git-parse-remote.sh +++ b/git-parse-remote.sh @@ -146,8 +146,12 @@ canon_refs_list_for_fetch () { else for merge_branch in $merge_branches do - [ "$remote" = "$merge_branch" ] && - dot_prefix= && break + if test "$remote" = "$merge_branch" || + test "$local" = "$merge_branch" + then + dot_prefix= + break + fi done fi case "$remote" in -- cgit v1.3