Why does setting PATCHTOOL="git" result in do_patch trying to look at git hooks in the host repo?


Sean McKay
 

Hi all,

 

I have a component in our build that’s pulling from an upstream git server, so I decided to set the PATCHTOOL=”git” so that it’s easier to determine in the local repository what patches have been applied (since using the git PATCHTOOL results in full commits, whereas quilt just makes a mess and everything goes into the child git repo as a giant unstaged change).

 

However, in testing, I’m hitting this failure if I’m building in a git worktree:

*** 0505:        os.mkdir(hooks_dir)

     0506:        commithook = os.path.join(hooks_dir, 'commit-msg')

     0507:        applyhook = os.path.join(hooks_dir, 'applypatch-msg')

     0508:        with open(commithook, 'w') as f:

     0509:            # NOTE: the formatting here is significant; if you change it you'll also need to

Exception: NotADirectoryError: [Errno 20] Not a directory: '/ws/mckays/zeus-test/.git/hooks'

 

Now, to be fair, it’s quite correct – that isn’t a directory, since that’s not how git worktrees operate.

I can probably come up with a patch to submit upstream to correct this behavior, but I can’t fathom why the patcher should logically be trying to do anything with the parent git repo for any reason. And I can solve this for git worktrees, but what if someone just has a tarball and isn’t trying to build inside git at all – wouldn’t they hit the same failure?

 

I’d appreciate any clarity you can provide. Thanks!!!

 

-Sean

 

 

Full stack trace:

The stack trace of python calls that resulted in this exception/failure was:

File: 'exec_python_func() autogenerated', lineno: 2, function: <module>

    0001:

*** 0002:patch_do_patch(d)

     0003:

File: '/ws/mckays/zeus-test/yocto/poky/meta/classes/patch.bbclass', lineno: 145, function: patch_do_patch

     0141:        except Exception as exc:

     0142:            bb.utils.remove(process_tmpdir, True)

     0143:            bb.fatal(str(exc))

     0144:        try:

*** 0145:            resolver.Resolve()

     0146:        except bb.BBHandledException as e:

     0147:            bb.utils.remove(process_tmpdir, True)

     0148:            bb.fatal(str(e))

     0149:

File: '/ws/mckays/zeus-test/yocto/poky/meta/lib/oe/patch.py', lineno: 716, function: Resolve

     0712:    def Resolve(self):

     0713:        olddir = os.path.abspath(os.curdir)

     0714:        os.chdir(self.patchset.dir)

     0715:        try:

*** 0716:            self.patchset.Push()

     0717:        except Exception:

     0718:            import sys

     0719:            os.chdir(olddir)

     0720:            raise

File: '/ws/mckays/zeus-test/yocto/poky/meta/lib/oe/patch.py', lineno: 267, function: Push

     0263:            else:

     0264:                next = 0

     0265:

     0266:            bb.note("applying patch %s" % self.patches[next])

*** 0267:            ret = self._applypatch(self.patches[next], force)

     0268:

     0269:            self._current = next

     0270:            return ret

     0271:

File: '/ws/mckays/zeus-test/yocto/poky/meta/lib/oe/patch.py', lineno: 505, function: _applypatch

     0501:        if os.path.lexists(hooks_dir_backup):

     0502:            raise Exception("Git hooks backup directory already exists: %s" % hooks_dir_backup)

     0503:        if os.path.lexists(hooks_dir):

     0504:            shutil.move(hooks_dir, hooks_dir_backup)

*** 0505:        os.mkdir(hooks_dir)

     0506:        commithook = os.path.join(hooks_dir, 'commit-msg')

     0507:        applyhook = os.path.join(hooks_dir, 'applypatch-msg')

     0508:        with open(commithook, 'w') as f:

     0509:            # NOTE: the formatting here is significant; if you change it you'll also need to

Exception: NotADirectoryError: [Errno 20] Not a directory: '/ws/mckays/zeus-test/.git/hooks'

 

Join yocto@lists.yoctoproject.org to automatically receive all group messages.