merge and reset: adjust for "reset --hard" messages
[gitweb.git] / git-parse-remote.sh
index 6ae534bf89a7a1fd0bfeee4248c37b4ea71290b9..f163821d033cc0dc81dcd7ce0af13a7e75986db1 100755 (executable)
@@ -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
                )
@@ -134,11 +132,12 @@ 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
+               set x $(expand_refs_wildcard "$@")
+               shift
                if test "$remote" = "$(get_default_remote)"
                then
                        curr_branch=$(git-symbolic-ref HEAD | \
@@ -146,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
@@ -173,10 +177,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/*) ;;
@@ -197,11 +197,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)