[oe-commits] [openembedded-core] branch jethro updated: lib/oe/patch: Make GitApplyTree._applypatch() support read-only .git/hooks

git at git.openembedded.org git at git.openembedded.org
Sun Mar 20 10:22:02 UTC 2016


rpurdie pushed a commit to branch jethro
in repository openembedded-core.

The following commit(s) were added to refs/heads/jethro by this push:
       new  09a2718   lib/oe/patch: Make GitApplyTree._applypatch() support read-only .git/hooks
09a2718 is described below

commit 09a2718cb030f8cce202ded0e823cadea4c71f6a
Author: Peter Kjellerstedt <peter.kjellerstedt at axis.com>
AuthorDate: Wed Jan 27 15:39:52 2016 +0100

    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.
    
    (From OE-Core master rev: a88d603b51a9ebb39210d54b667519acfbe465c3)
    
    Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt at axis.com>
    Signed-off-by: Ross Burton <ross.burton at intel.com>
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
    Signed-off-by: Robert Yang <liezhi.yang at windriver.com>
---
 meta/lib/oe/patch.py | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py
index 2bf501e..c25d3c7 100644
--- a/meta/lib/oe/patch.py
+++ b/meta/lib/oe/patch.py
@@ -383,14 +383,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
@@ -439,12 +440,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):

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list