Add documentation for show-branch --topics
[gitweb.git] / git-parse-remote.sh
index c325ef761e4c558ab5c7c560da942e127e1be040..bc881cc5f9d932c40f10bf0448aafa3263724c35 100755 (executable)
@@ -90,6 +90,41 @@ 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
+               lref=${ref#'+'}
+               # a non glob pattern is given back as-is.
+               expr "z$lref" : 'zrefs/.*/\*:refs/.*/\*$' >/dev/null || {
+                       echo "$ref"
+                       continue
+               }
+
+               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" |
+               sed -e '/\^{}$/d' |
+               (
+                       IFS='   '
+                       while read sha1 name
+                       do
+                               # ignore the ones that do not start with $from
+                               mapped=${name#"$from"}
+                               test "z$name" = "z$mapped" && continue
+                               echo "${local_force}${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
@@ -97,6 +132,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
@@ -107,6 +144,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
@@ -132,6 +171,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/*) ;;
@@ -152,6 +195,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)