]> git.e2factory.org Git - e2factory.git/commitdiff
generic_git: add a few helpers for formatting refs
authorTobias Ulmer <tu@emlix.com>
Fri, 9 Nov 2018 16:22:44 +0000 (17:22 +0100)
committerTobias Ulmer <tu@emlix.com>
Mon, 10 Dec 2018 17:00:11 +0000 (18:00 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/generic_git.lua

index d8158d0aca18f717c83bab444f1d54460081073b..83c0580d37d50e8dbbaca5710538389cae48fb92 100644 (file)
@@ -99,6 +99,36 @@ end
 
 local refs_heads = generic_git.refs_heads
 
+-- Helper to get the default remote string.
+-- Trivial function to keep information in one place.
+-- @param remote, defaults to "origin".
+-- @return remote string.
+function generic_git.refs_remote(remote)
+    return remote or "origin"
+end
+
+--- Helper to generate refs/remotes/<remote>/<branch>
+-- @param branch Branch
+-- @param remote Remote, defaults to refs_remote().
+-- @return refs/remotes/remote/branch
+function generic_git.refs_remotes(branch, remote)
+    remote = generic_git.refs_remote(remote)
+    assertIsStringN(branch)
+    assertIsStringN(remote)
+    return "refs/remotes/"..remote.."/"..branch
+end
+
+--- Helper to generate <remote>/<branch>
+--@param branch Branch
+--@param remote Remote, defaults to refs_remote().
+--@return remote/branch string
+function generic_git.refs_remote_heads(branch, remote)
+    remote = generic_git.refs_remote(remote)
+    assertIsStringN(branch)
+    assertIsStringN(remote)
+    return remote.."/"..branch
+end
+
 --- Create argument vector for calling git.
 -- Defaults: If git_dir is given and the default for work_tree is requested,
 -- it's assumed to be one directory level up. If work_tree is given and the