Commit 901cc930bc17c29760a4b856529dea7391be648c

Thomas de Grivel 2023-02-25T15:58:31

logging

diff --git a/bin/rbpkg_ci b/bin/rbpkg_ci
index bdd2b3a..675978b 100755
--- a/bin/rbpkg_ci
+++ b/bin/rbpkg_ci
@@ -38,8 +38,8 @@ def rbpkg_ci
     usage
   end
   repo = shift
-  branch = shift
-  commit = shift
+  branch = $ARGS[0] ? shift : nil
+  commit = $ARGS[0] ? shift : nil
   usage unless $ARGS == []
   Rbpkg::Repos.repo(repo).ci(branch, commit)
 end
diff --git a/lib/rbpkg.rb b/lib/rbpkg.rb
index 8c47031..1e6a94c 100644
--- a/lib/rbpkg.rb
+++ b/lib/rbpkg.rb
@@ -132,7 +132,7 @@ module Rbpkg
      lock_dir,
      log_dir
     ].each do |d|
-      ensure_dir(d)
+      FileUtils.mkdir_p(d)
     end
     $log = Rbpkg::Log
     Rbpkg::Log.init(name)
diff --git a/lib/rbpkg/log.rb b/lib/rbpkg/log.rb
index fda3a6a..7a5f556 100644
--- a/lib/rbpkg/log.rb
+++ b/lib/rbpkg/log.rb
@@ -86,7 +86,9 @@ EOF
           log.status = :ko
         end
         verbose(-1, status_message_ko)
-        remove_all
+        remove_all.each do |name, log|
+          log.put_layout
+        end
       end
     end
 
@@ -103,7 +105,9 @@ EOF
           log.status = :ok
         end
         verbose(3, status_message_ok)
-        remove_all
+        remove_all.each do |name, log|
+          log.put_layout
+        end
       end
     end
 
diff --git a/lib/rbpkg/repo.rb b/lib/rbpkg/repo.rb
index a18e29a..35d890f 100644
--- a/lib/rbpkg/repo.rb
+++ b/lib/rbpkg/repo.rb
@@ -38,14 +38,23 @@ class Rbpkg::Repo
   end
 
   def ci(ref, commit)
-    verbose(3, "repo(#{name.inspect}).ci(#{commit.inspect})")
+    verbose(3, "repo(#{name.inspect}).ci(#{ref.inspect}, #{commit.inspect})")
+    unless ref
+      checkout(branch)
+      ref = branch
+    end
+    unless commit
+      pull
+      commit = hash
+    end
     Rbpkg::Log.add(ci_log_name_ref(ref))
     Rbpkg::Log.add(ci_log_name_commit(commit))
     sh_name = sh_quote(name)
-    sh_profile = sh_quote(ci_dir + '/etc/profile')
+    sh_ci_dir = sh_quote(ci_dir)
+    sh_ci_profile = sh_quote(ci_dir + '/etc/profile')
     if File.directory?(ci_dir)
       Rbpkg::Log.add("rbpkg_ci.#{name}.upgrade")
-      if cmd ". #{sh_profile} && rbpkg checkout #{sh_quote(commit)} #{sh_name} && rbpkg upgrade #{sh_name}"
+      if cmd "export RBPKG_DIR=#{sh_ci_dir} && . #{sh_ci_profile} && rbpkg checkout #{sh_quote(commit)} #{sh_name} && rbpkg upgrade #{sh_name}"
         Rbpkg::Log.ok("rbpkg_ci.#{name}.upgrade")
       else
         Rbpkg::Log.ko("rbpkg_ci.#{name}.upgrade")
@@ -53,7 +62,7 @@ class Rbpkg::Repo
     end
     Rbpkg::Log.add("rbpkg_ci.#{name}.install")
     cmd! "rbpkg_bootstrap -f #{sh_quote(ci_dir)}"
-    cmd! ". #{sh_profile} && rbpkg clone #{sh_name} && rbpkg checkout #{sh_quote(commit)} #{sh_name} && rbpkg install #{sh_name}"
+    cmd! "export RBPKG_DIR=#{sh_ci_dir} && . #{sh_ci_profile} && rbpkg clone #{sh_name} && rbpkg checkout #{sh_quote(commit)} #{sh_name} && rbpkg install #{sh_name}"
     Rbpkg::Log.ok("rbpkg_ci.#{name}.install")
     Rbpkg::Log.ok(ci_log_name_commit(commit))
     Rbpkg::Log.ok(ci_log_name_ref(ref))