github-merge-pr: fix loading .config if symbolic link is used
[maintainer-tools.git] / patchwork-apply.sh
index 5f293306cc6fe751c1ac925d34a626c624fa9ab3..5506adbfe4513d95cd9c99f00f98b2bca0a796dc 100755 (executable)
@@ -1,5 +1,7 @@
 #!/usr/bin/env bash
 
+SED=$(which gsed 2>/dev/null); SED=${SED:-sed}
+
 yesno() {
        local prompt="$1"
        local default="${2:-n}"
@@ -20,13 +22,13 @@ fetch() {(
        mkdir "pwclient.get.$$"
        cd "pwclient.get.$$"
        pwclient get "$1"
-       mv *.patch "../$1.patch"
+       mv * "../$1.patch"
        cd ..
        rmdir "pwclient.get.$$"
 )}
 
 get_date() {
-       date +"%a, %d %b %Y %H:%M:%S %z" | sed -e 's|, 0|, |'
+       date +"%a, %d %b %Y %H:%M:%S %z" | $SED -e 's|, 0|, |'
 }
 
 get_subject() {
@@ -34,11 +36,11 @@ get_subject() {
        local IFS="
 "
 
-       for line in $(sed -ne '/^Subject: */ { s/^Subject: *//p; :next; n; s/^ \+//p; t next; b }' "$1"); do
+       for line in $($SED -ne '/^Subject: */ { s/^Subject: *//p; :next; n; s/^ \+//p; t next; b }' "$1"); do
                subject="$subject$line"
        done
 
-       printf "%s\n" "$subject" | sed -e 's/^\[.*\] *//'
+       printf "%s\n" "$subject" | $SED -e 's/^\[.*\] \+//'
 }
 
 get_hdr_list() {
@@ -49,15 +51,15 @@ get_hdr_list() {
        local IFS=",
 "
 
-       for addr in $(sed -ne "/^$field: */ { s/^$field: *//p; :next; n; s/^ \\+//p; t next; b }" "$file"); do
-               list="${list:+$list, }$(echo "$addr" | sed -e 's/^ \+//; s/ \+$//')"
+       for addr in $($SED -ne "/^$field: */ { s/^$field: *//p; :next; n; s/^ \\+//p; t next; b }" "$file"); do
+               list="${list:+$list, }$(echo "$addr" | $SED -e 's/^ \+//; s/ \+$//')"
        done
 
        [ -n "$list" ] && printf "%s: %s\n" "$field" "$list"
 }
 
 get_hdr() {
-       sed -ne "s/^$2: *//p" "$1" | head -n1
+       $SED -ne "s/^$2: *//p" "$1" | head -n1
 }
 
 format_reply() {
@@ -99,27 +101,24 @@ format_reply() {
        esac
 
        case "$remote_host" in
-               git.lede-project.org)
+               git.openwrt.org|git.lede-project.org)
                        case "$remote_repo" in
-                               source.git)
-                                       echo "Merged into ${remote_ref##*/} with"
+                               source.git|openwrt/openwrt.git)
+                                       echo "Merged into ${remote_ref##*/}."
                                ;;
-                               lede/*/staging.git)
-                                       echo "Merged into my staging tree with"
+                               lede/*/staging.git|openwrt/staging/*.git)
+                                       echo "Merged into my staging tree."
                                ;;
                                *)
-                                       echo "Merged into ${remote_repo:-the repository}, branch ${remote_ref##*/} with"
+                                       echo "Merged into ${remote_repo:-the repository}, branch ${remote_ref##*/}."
                                ;;
                        esac
                ;;
                *)
-                       echo "Merged with"
+                       echo "Merged."
                ;;
        esac
 
-       echo "http://$remote_host/?p=$remote_repo;a=commitdiff;h=$(git log -1 --format=%h)."
-       echo ""
-
        echo "Thank you!"
        echo ""
 }