summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe
diff options
context:
space:
mode:
authorPeter Kjellerstedt <peter.kjellerstedt@axis.com>2016-01-27 15:39:52 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-01-30 11:37:01 +0000
commiteb7e554cbd6194203e885e7e0ba304c01c647f06 (patch)
tree2269c05139cdf1936e40f23a58420376460927e0 /meta/lib/oe
parent3ed566e1006a74c8a5581a7036c1b9c9285821f7 (diff)
downloadpoky-eb7e554cbd6194203e885e7e0ba304c01c647f06.tar.gz
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 rev: a88d603b51a9ebb39210d54b667519acfbe465c3) Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oe')
-rw-r--r--meta/lib/oe/patch.py26
1 files changed, 12 insertions, 14 deletions
diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py
index 2255ce437b..4e77168dab 100644
--- a/meta/lib/oe/patch.py
+++ b/meta/lib/oe/patch.py
@@ -411,14 +411,15 @@ class GitApplyTree(PatchTree):
411 reporoot = (runcmd("git rev-parse --show-toplevel".split(), self.dir) or '').strip() 411 reporoot = (runcmd("git rev-parse --show-toplevel".split(), self.dir) or '').strip()
412 if not reporoot: 412 if not reporoot:
413 raise Exception("Cannot get repository root for directory %s" % self.dir) 413 raise Exception("Cannot get repository root for directory %s" % self.dir)
414 commithook = os.path.join(reporoot, '.git', 'hooks', 'commit-msg') 414 hooks_dir = os.path.join(reporoot, '.git', 'hooks')
415 commithook_backup = commithook + '.devtool-orig' 415 hooks_dir_backup = hooks_dir + '.devtool-orig'
416 applyhook = os.path.join(reporoot, '.git', 'hooks', 'applypatch-msg') 416 if os.path.lexists(hooks_dir_backup):
417 applyhook_backup = applyhook + '.devtool-orig' 417 raise Exception("Git hooks backup directory already exists: %s" % hooks_dir_backup)
418 if os.path.exists(commithook): 418 if os.path.lexists(hooks_dir):
419 shutil.move(commithook, commithook_backup) 419 shutil.move(hooks_dir, hooks_dir_backup)
420 if os.path.exists(applyhook): 420 os.mkdir(hooks_dir)
421 shutil.move(applyhook, applyhook_backup) 421 commithook = os.path.join(hooks_dir, 'commit-msg')
422 applyhook = os.path.join(hooks_dir, 'applypatch-msg')
422 with open(commithook, 'w') as f: 423 with open(commithook, 'w') as f:
423 # NOTE: the formatting here is significant; if you change it you'll also need to 424 # NOTE: the formatting here is significant; if you change it you'll also need to
424 # change other places which read it back 425 # change other places which read it back
@@ -467,12 +468,9 @@ class GitApplyTree(PatchTree):
467 os.remove(tmpfile) 468 os.remove(tmpfile)
468 return output 469 return output
469 finally: 470 finally:
470 os.remove(commithook) 471 shutil.rmtree(hooks_dir)
471 os.remove(applyhook) 472 if os.path.lexists(hooks_dir_backup):
472 if os.path.exists(commithook_backup): 473 shutil.move(hooks_dir_backup, hooks_dir)
473 shutil.move(commithook_backup, commithook)
474 if os.path.exists(applyhook_backup):
475 shutil.move(applyhook_backup, applyhook)
476 474
477 475
478class QuiltTree(PatchSet): 476class QuiltTree(PatchSet):