Message ID | 20230823134135.3037433-1-jstephan@baylibre.com |
---|---|
State | Accepted, archived |
Commit | f74879dd95b19504ce8a8554636d2310d0336806 |
Headers | show |
Series | [1/2] patch.py: use --absolute-git-dir instead of --show-toplevel to retrieve gitdir | expand |
Thanks, this has been a problem for a long time. Alex On Wed, 23 Aug 2023 at 15:41, Julien Stephan <jstephan@baylibre.com> wrote: > > [YOCTO #14141] > > Currently the gitdir is manually constructed using `git > rev-parse --show-toplevel` and appending `.git`. This is most of the time > correct but not always: `.git` can be a file with the following content: > > gitdir: <some_folder> > > This is the case for submodules, so when using devtool modify on a recipe > using submodules *and* patching files inside one of the submodules, do_patch > fails with the following error: > > ERROR: Error executing a python function in exec_func_python() autogenerated: > > The stack trace of python calls that resulted in this exception/failure was: > File: 'exec_func_python() autogenerated', lineno: 2, function: <module> > 0001: > *** 0002:patch_do_patch(d) > 0003: > File: '<..>/poky/meta/classes-global/patch.bbclass', lineno: 157, function: patch_do_patch > 0153: except Exception as exc: > 0154: bb.utils.remove(process_tmpdir, True) > 0155: bb.fatal("Importing patch '%s' with striplevel '%s'\n%s" % (parm['patchname'], parm['striplevel'], repr(exc).replace("\\n", "\n"))) > 0156: try: > *** 0157: resolver.Resolve() > 0158: except bb.BBHandledException as e: > 0159: bb.utils.remove(process_tmpdir, True) > 0160: bb.fatal("Applying patch '%s' on target directory '%s'\n%s" % (parm['patchname'], patchdir, repr(e).replace("\\n", "\n"))) > 0161: > File: '<..>/poky/meta/lib/oe/patch.py', lineno: 769, function: Resolve > 0765: def Resolve(self): > 0766: olddir = os.path.abspath(os.curdir) > 0767: os.chdir(self.patchset.dir) > 0768: try: > *** 0769: self.patchset.Push() > 0770: except Exception: > 0771: import sys > 0772: os.chdir(olddir) > 0773: raise > File: '<..>/poky/meta/lib/oe/patch.py', lineno: 274, function: Push > 0270: else: > 0271: next = 0 > 0272: > 0273: bb.note("applying patch %s" % self.patches[next]) > *** 0274: ret = self._applypatch(self.patches[next], force) > 0275: > 0276: self._current = next > 0277: return ret > 0278: > File: '<..>/poky/meta/lib/oe/patch.py', lineno: 556, function: _applypatch > 0552: if os.path.lexists(hooks_dir_backup): > 0553: raise Exception("Git hooks backup directory already exists: %s" % hooks_dir_backup) > 0554: if os.path.lexists(hooks_dir): > 0555: shutil.move(hooks_dir, hooks_dir_backup) > *** 0556: os.mkdir(hooks_dir) > 0557: commithook = os.path.join(hooks_dir, 'commit-msg') > 0558: applyhook = os.path.join(hooks_dir, 'applypatch-msg') > 0559: with open(commithook, 'w') as f: > 0560: # NOTE: the formatting here is significant; if you change it you'll also need to > Exception: NotADirectoryError: [Errno 20] Not a directory: '<..>/build/tmp/work/core2-64-poky-linux/vulkan-samples/git/devtooltmp-n87_zx1i/workdir/git/third_party/spdlog/.git/hooks' > > Using `git rev-parse --absolute-git-dir` instead of `git rev-parse > --show-toplevel` ensure we get the correct gitdir > > Signed-off-by: Julien Stephan <jstephan@baylibre.com> > --- > meta/lib/oe/patch.py | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py > index 5990896fdc5..a02ff8eafb6 100644 > --- a/meta/lib/oe/patch.py > +++ b/meta/lib/oe/patch.py > @@ -544,10 +544,10 @@ class GitApplyTree(PatchTree): > return runcmd(["sh", "-c", " ".join(shellcmd)], self.dir) > > # Add hooks which add a pointer to the original patch file name in the commit message > - reporoot = (runcmd("git rev-parse --show-toplevel".split(), self.dir) or '').strip() > + reporoot = (runcmd("git rev-parse --absolute-git-dir".split(), self.dir) or '').strip() > if not reporoot: > raise Exception("Cannot get repository root for directory %s" % self.dir) > - hooks_dir = os.path.join(reporoot, '.git', 'hooks') > + hooks_dir = os.path.join(reporoot, '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) > -- > 2.41.0 > > > -=-=-=-=-=-=-=-=-=-=-=- > Links: You receive all messages sent to this group. > View/Reply Online (#186579): https://lists.openembedded.org/g/openembedded-core/message/186579 > Mute This Topic: https://lists.openembedded.org/mt/100914685/1686489 > Group Owner: openembedded-core+owner@lists.openembedded.org > Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [alex.kanavin@gmail.com] > -=-=-=-=-=-=-=-=-=-=-=- >
diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py index 5990896fdc5..a02ff8eafb6 100644 --- a/meta/lib/oe/patch.py +++ b/meta/lib/oe/patch.py @@ -544,10 +544,10 @@ class GitApplyTree(PatchTree): return runcmd(["sh", "-c", " ".join(shellcmd)], self.dir) # Add hooks which add a pointer to the original patch file name in the commit message - reporoot = (runcmd("git rev-parse --show-toplevel".split(), self.dir) or '').strip() + reporoot = (runcmd("git rev-parse --absolute-git-dir".split(), self.dir) or '').strip() if not reporoot: raise Exception("Cannot get repository root for directory %s" % self.dir) - hooks_dir = os.path.join(reporoot, '.git', 'hooks') + hooks_dir = os.path.join(reporoot, '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)
[YOCTO #14141] Currently the gitdir is manually constructed using `git rev-parse --show-toplevel` and appending `.git`. This is most of the time correct but not always: `.git` can be a file with the following content: gitdir: <some_folder> This is the case for submodules, so when using devtool modify on a recipe using submodules *and* patching files inside one of the submodules, do_patch fails with the following error: ERROR: Error executing a python function in exec_func_python() autogenerated: The stack trace of python calls that resulted in this exception/failure was: File: 'exec_func_python() autogenerated', lineno: 2, function: <module> 0001: *** 0002:patch_do_patch(d) 0003: File: '<..>/poky/meta/classes-global/patch.bbclass', lineno: 157, function: patch_do_patch 0153: except Exception as exc: 0154: bb.utils.remove(process_tmpdir, True) 0155: bb.fatal("Importing patch '%s' with striplevel '%s'\n%s" % (parm['patchname'], parm['striplevel'], repr(exc).replace("\\n", "\n"))) 0156: try: *** 0157: resolver.Resolve() 0158: except bb.BBHandledException as e: 0159: bb.utils.remove(process_tmpdir, True) 0160: bb.fatal("Applying patch '%s' on target directory '%s'\n%s" % (parm['patchname'], patchdir, repr(e).replace("\\n", "\n"))) 0161: File: '<..>/poky/meta/lib/oe/patch.py', lineno: 769, function: Resolve 0765: def Resolve(self): 0766: olddir = os.path.abspath(os.curdir) 0767: os.chdir(self.patchset.dir) 0768: try: *** 0769: self.patchset.Push() 0770: except Exception: 0771: import sys 0772: os.chdir(olddir) 0773: raise File: '<..>/poky/meta/lib/oe/patch.py', lineno: 274, function: Push 0270: else: 0271: next = 0 0272: 0273: bb.note("applying patch %s" % self.patches[next]) *** 0274: ret = self._applypatch(self.patches[next], force) 0275: 0276: self._current = next 0277: return ret 0278: File: '<..>/poky/meta/lib/oe/patch.py', lineno: 556, function: _applypatch 0552: if os.path.lexists(hooks_dir_backup): 0553: raise Exception("Git hooks backup directory already exists: %s" % hooks_dir_backup) 0554: if os.path.lexists(hooks_dir): 0555: shutil.move(hooks_dir, hooks_dir_backup) *** 0556: os.mkdir(hooks_dir) 0557: commithook = os.path.join(hooks_dir, 'commit-msg') 0558: applyhook = os.path.join(hooks_dir, 'applypatch-msg') 0559: with open(commithook, 'w') as f: 0560: # NOTE: the formatting here is significant; if you change it you'll also need to Exception: NotADirectoryError: [Errno 20] Not a directory: '<..>/build/tmp/work/core2-64-poky-linux/vulkan-samples/git/devtooltmp-n87_zx1i/workdir/git/third_party/spdlog/.git/hooks' Using `git rev-parse --absolute-git-dir` instead of `git rev-parse --show-toplevel` ensure we get the correct gitdir Signed-off-by: Julien Stephan <jstephan@baylibre.com> --- meta/lib/oe/patch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)