From 696b4316dadc25c9bd78cdc09397913c56f32ac1 Mon Sep 17 00:00:00 2001
From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Sat, 18 Apr 2020 18:54:08 +0200
Subject: [PATCH] gluon-web-autoupdater: use human-readable names as branch
 labels, sort by label

Use the value of the `name` site.conf field as label (it was
accidentally unused before).

Our site.conf currently doesn't define a specific order for the branch
entries. To avoid changing branch orders, sort entries by this label.

Fixes: #1961
---
 .../config-mode/model/admin/autoupdater.lua     | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/package/gluon-web-autoupdater/luasrc/lib/gluon/config-mode/model/admin/autoupdater.lua b/package/gluon-web-autoupdater/luasrc/lib/gluon/config-mode/model/admin/autoupdater.lua
index adf7cbd6d..a78e76e32 100644
--- a/package/gluon-web-autoupdater/luasrc/lib/gluon/config-mode/model/admin/autoupdater.lua
+++ b/package/gluon-web-autoupdater/luasrc/lib/gluon/config-mode/model/admin/autoupdater.lua
@@ -22,11 +22,18 @@ function o:write(data)
 end
 
 o = s:option(ListValue, "branch", translate("Branch"))
-uci:foreach("autoupdater", "branch",
-	function (section)
-		o:value(section[".name"])
-	end
-)
+
+local branches = {}
+uci:foreach("autoupdater", "branch", function(branch)
+	table.insert(branches, branch)
+end)
+table.sort(branches, function(a, b)
+	return a.name < b.name
+end)
+for _, branch in ipairs(branches) do
+	o:value(branch[".name"], branch.name)
+end
+
 o.default = uci:get("autoupdater", autoupdater, "branch")
 function o:write(data)
 	uci:set("autoupdater", autoupdater, "branch", data)
-- 
GitLab