]> git.e2factory.org Git - e2factory.git/commitdiff
generic_git: make list_refs() a public interface
authorTobias Ulmer <tu@emlix.com>
Thu, 28 Feb 2019 18:58:46 +0000 (19:58 +0100)
committerTobias Ulmer <tu@emlix.com>
Thu, 28 Feb 2019 19:01:59 +0000 (20:01 +0100)
Optionally takes a git remote string instead of the default "origin"

Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/generic_git.lua

index f398e6d405f1c8b30e8fd3be5e12f072d644e393..1eceadda3d9d026ce16388de7aeefbf2f07394d0 100644 (file)
@@ -210,25 +210,29 @@ function generic_git.git(argv, workdir)
     return true, nil, table.concat(out)
 end
 
+
 --- Return a table containing pairs of commit id and refs of the local
 -- or remote repository.
 -- @param git_dir Path to GIT_DIR.
--- @param remote True for the remote default repository (usually "origin"),
---               false for the local repository.
+-- @param remote True for the default remote repository,
+--               string to specify a remote, and false for the local repository.
+-- @return Error object on failure, otherwise nil
 -- @return Table containing tables of "id", "ref" pairs, or false on error.
--- @return Error object on failure.
-local function get_refs(git_dir, remote)
+function generic_git.list_refs(git_dir, remote)
     assertIsStringN(git_dir)
-    assertIsBoolean(remote)
+    assert(type(remote) == "string" or type(remote) == "boolean")
 
     local rc, re, e, argv, out, t, emsg
 
-    emsg = "error in get_refs()"
+    emsg = "error listing git refs"
 
     argv = generic_git.git_new_argv(git_dir, false)
     if remote then
+        if type(remote) == "boolean" then
+            remote = generic_git.refs_remote()
+        end
         table.insert(argv, "ls-remote")
-        table.insert(argv, "origin")
+        table.insert(argv, remote)
     else
         table.insert(argv, "show-ref")
         table.insert(argv, "--head") -- ls-remote does this by default
@@ -270,7 +274,7 @@ end
 function generic_git.lookup_id(git_dir, remote, ref)
     local rc, re, t
 
-    rc, re, t = get_refs(git_dir, remote)
+    rc, re, t = generic_git.list_refs(git_dir, remote)
     if not rc then
         return false, re
     end
@@ -305,7 +309,7 @@ function generic_git.lookup_ref(git_dir, remote, id, filter)
 
     local rc, re, t
 
-    rc, re, t = get_refs(git_dir, remote)
+    rc, re, t = generic_git.list_refs(git_dir, remote)
     if not rc then
         return false, re
     end