Skip to contentSkip to conversation

Make devtool handle read-only .git/hooks directories

PATCH New Peter Kjellerstedt 1 participant 2 messages Jan 27, 2016

lore
Share & tools
lore
#0 lore raw

cover Make devtool handle read-only .git/hooks directories

When running "devtool extract <recipe> <dir>", it failed for us if the recipe contained any patches. This was due to devtools modification of the commit-msg and applypatch-msg Git hooks.

We have a bit unusal setup where .git/hooks is a symbolic link to a directory in /usr/share, which means that it is not writable by the user. This of course caused devtool to fail when it tried to modify the hooks.

The solution provided here temporarily moves away the .git/hooks directory (or link) instead, which should be safe since the .git directory should be writable.

We also need this applied to Jethro. Do I need to supply a separate patch for that?

//Peter

The following changes since commit 3d2c0f5902cacf9d8544bf263b51ef0dd1a7218c:

cmake: update to 3.4.2 (2016-01-26 22:49:40 +0000)

are available in the git repository at:

git://git.yoctoproject.org/poky-contrib pkj/devtool_hooks
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=pkj/devtool_hooks

Peter Kjellerstedt (1):
lib/oe/patch: Make GitApplyTree._applypatch() support read-only
.git/hooks

 meta/lib/oe/patch.py | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)
Signature · 1 line
2.1.0
#1 lore raw

PATCH 1/1 lib/oe/patch: Make GitApplyTree._applypatch() support read-only .git/hooks

Rather than modifying files in .git/hooks, which can be read-only (e.g., if it is a link to a directory in /usr/share), move away the entire .git/hooks directory temporarily.

---
 meta/lib/oe/patch.py | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)
meta/lib/oe/patch.py +12 -14
index 2255ce4..4e77168 100644
@@ -411,14 +411,15 @@ class GitApplyTree(PatchTree):
         reporoot = (runcmd("git rev-parse --show-toplevel".split(), self.dir) or '').strip()
         if not reporoot:
             raise Exception("Cannot get repository root for directory %s" % self.dir)
-        commithook = os.path.join(reporoot, '.git', 'hooks', 'commit-msg')
-        commithook_backup = commithook + '.devtool-orig'
-        applyhook = os.path.join(reporoot, '.git', 'hooks', 'applypatch-msg')
-        applyhook_backup = applyhook + '.devtool-orig'
-        if os.path.exists(commithook):
-            shutil.move(commithook, commithook_backup)
-        if os.path.exists(applyhook):
-            shutil.move(applyhook, applyhook_backup)
+        hooks_dir = os.path.join(reporoot, '.git', 'hooks')
+        hooks_dir_backup = hooks_dir + '.devtool-orig'
+        if os.path.lexists(hooks_dir_backup):
+            raise Exception("Git hooks backup directory already exists: %s" % hooks_dir_backup)
+        if os.path.lexists(hooks_dir):
+            shutil.move(hooks_dir, hooks_dir_backup)
+        os.mkdir(hooks_dir)
+        commithook = os.path.join(hooks_dir, 'commit-msg')
+        applyhook = os.path.join(hooks_dir, 'applypatch-msg')
         with open(commithook, 'w') as f:
             # NOTE: the formatting here is significant; if you change it you'll also need to
             # change other places which read it back
@@ -467,12 +468,9 @@ class GitApplyTree(PatchTree):
                     os.remove(tmpfile)
                 return output
         finally:
-            os.remove(commithook)
-            os.remove(applyhook)
-            if os.path.exists(commithook_backup):
-                shutil.move(commithook_backup, commithook)
-            if os.path.exists(applyhook_backup):
-                shutil.move(applyhook_backup, applyhook)
+            shutil.rmtree(hooks_dir)
+            if os.path.lexists(hooks_dir_backup):
+                shutil.move(hooks_dir_backup, hooks_dir)
 
 
 class QuiltTree(PatchSet):
Signature · 1 line
2.1.0