Watchbot does not support the smart git-over-http protocol, making
it unable to watch repositories hosted by Github and other services.
This commit adds support for the smart git-over-http protocol to
watchbot.
return 0
}
-fetch_head_remote() {
+fetch_head_smart_http() {
+ local watch="$1"
+
+ local repository
+ local branch
+ local url
+ local re
+ local data
+ local ref
+
+ repository=$(watch_to_repository "$watch")
+ branch=$(watch_to_branch "$watch")
+
+ re="00[0-9a-f]{2}\\K[0-9a-f]{40} refs/heads/$branch"
+ url="$repository/info/refs?service=git-upload-pack"
+
+ if ! data=$(curl --get --silent --location "$url" 2>/dev/null |
+ grep -oP "$re" --binary-files=text); then
+ return 1
+ fi
+
+ ref="${data%% *}"
+ echo "$ref"
+ return 0
+}
+
+fetch_head_dumb_http() {
local watch="$1"
local repository
return 0
}
+fetch_head_remote() {
+ local watch="$1"
+
+ local head
+
+ if ! head=$(fetch_head_smart_http "$watch"); then
+ if ! head=$(fetch_head_dumb_http "$watch"); then
+ return 1
+ fi
+ fi
+
+ echo "$head"
+ return 0
+}
+
fetch_head_local() {
local watch="$1"