]> git.e2factory.org Git - e2factory.git/commitdiff
Simplify generic_git.verify_remote_tag() using new lookup functions
authorTobias Ulmer <tu@emlix.com>
Tue, 5 Nov 2013 19:14:07 +0000 (20:14 +0100)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:01:23 +0000 (15:01 +0100)
Gets rid of the temporary remote tag that could potentially destroy a
valid tag if there was a name collision.

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

index e65f8a063e1ad59a931c9d6034ef3ba563d9d6c4..034aa3d0f8b733b065e43eeb4a4aebb43aaecc77 100644 (file)
@@ -686,50 +686,29 @@ end
 -- @return Error object on failure.
 function generic_git.verify_remote_tag(gitdir, tag)
     local e = err.new("verifying remote tag")
-    local rc, re, rtag, argv
+    local rc, re, rtag, argv, rid, lid
 
-    -- temporary local name for remote tag
-    rtag = string.format("%s.remote", tag)
-
-    -- fetch the remote tag as rtag
-    argv = git_new_argv2(gitdir, false, "fetch", "origin")
-    table.insert(argv, string.format("refs/tags/%s:refs/tags/%s", tag, rtag))
-
-    rc, re = generic_git.git(argv)
+    rc, re, rid = generic_git.lookup_id(gitdir, true, "refs/tags/" .. tag)
     if not rc then
-        e = err.new("remote tag %q is not available", tag)
         return false, e:cat(re)
     end
 
-    -- before leaving, remove the temporary rtag
-    local function cleanup_rtag(gitdir, rtag)
-        local argv = git_new_argv2(gitdir, false, "tag", "-d", rtag)
-        generic_git.git(argv)
-    end
-
-    local rc, re, lid = generic_git.git_rev_list1(gitdir, tag)
-    if not rc then
-        cleanup_rtag(rtag)
-        return false, e:cat(re)
-    elseif lid == "" then
-        cleanup_rtag(rtag)
-        re = err.new("can not find commit ID for local tag %q in %q",
+    if not rid then
+        re = err.new("can not find commit ID for remote tag %q in %q",
             gitdir, tag)
         return false, e:cat(re)
     end
 
-    local rc, re, rid = generic_git.git_rev_list1(gitdir, rtag)
+    rc, re, lid = generic_git.lookup_id(gitdir, false, "refs/tags/" .. tag)
     if not rc then
-        cleanup_rtag(rtag)
-        return false, e:cat(re)
-    elseif rid == "" then
-        cleanup_rtag(rtag)
-        re = err.new("can not find commit ID for remote tag %q in %q",
-            gitdir, tag --[[ not rtag]])
         return false, e:cat(re)
     end
 
-    cleanup_rtag(rtag)
+    if rid ~= lid then
+        re = err.new("can not find commit ID for local tag %q in %q",
+            gitdir, tag)
+        return false, e:cat(re)
+    end
 
     if lid ~= rid then
         return false, e:append(