Don't pass a path removal parameter to git am/git apply since GitApplyTree
always applies patches from the root of the git repo, not from each
individual patchdir (like quilt).

GitApplyTree uses `git rev-parse --show-toplevel` to find the root of
the repo no matter which patchdir is passed into the GitApplyTree instance.
In most cases, this works fine when applying patches since the three-way
merge can figure out where the patch should be applied to existing files
based on the history, even if the file paths are excessively stripped.

An exception to this occurs if a patch adds a new file to the repo
and a custom ${S} has been set to a subdirectory of the repo such
that the patch requires a non-default striplevel parameter.

When processed by GitApplyTree, the patch will have its striplevel
parameter given to git even though it's applied at the root of the
tree.

For example, consider a patch that adds a new file src/foo to a repo.

  --- /dev/null
  +++ b/src/foo
  @@ -0,0 +1 @@
  +new file test

The recipe sets S = "${WORKDIR}/git/src" and the patch is added to SRC_URI
using "striplevel=2" since the default patch tool, quilt, applies each
patch at its patchdir, which defaults to ${S}.

When the GitApplyTree patch class is used (for example, through devtool),
the root of the repo is passed to git as the work tree, in addition to the
path removal paramter.  In the case above, GitApplyTree creates
${WORKDIR}/git/foo instead of ${WORKDIR}/git/src/foo.

Interestingly enough, you can take a more typical patch example that only
changes existing files (instead of adding a new file) and remove the -3
argument from the git am/git apply commands issued by GitApplyTree.  In
this scenario, the patch will also fail to apply because the path removal
arg is still being passed, and the resulting path does not exist.

Since GitApplyTree always applies from the root of the repo, it should
ignore any striplevel arguments.
---
 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 2b1eee1003..2e45a7ef89 100644
--- a/meta/lib/oe/patch.py
+++ b/meta/lib/oe/patch.py
@@ -517,7 +517,7 @@ class GitApplyTree(PatchTree):
             try:
                 shellcmd = [patchfilevar, "git", "--work-tree=%s" % reporoot]
                 self.gitCommandUserOptions(shellcmd, self.commituser, 
self.commitemail)
-                shellcmd += ["am", "-3", "--keep-cr", "-p%s" % 
patch['strippath']]
+                shellcmd += ["am", "-3", "--keep-cr"]
                 return _applypatchhelper(shellcmd, patch, force, reverse, run)
             except CmdError:
                 # Need to abort the git am, or we'll still be within it at the 
end
@@ -534,7 +534,7 @@ class GitApplyTree(PatchTree):
                 runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
 
                 # Fall back to git apply
-                shellcmd = ["git", "--git-dir=%s" % reporoot, "apply", "-p%s" 
% patch['strippath']]
+                shellcmd = ["git", "--git-dir=%s" % reporoot, "apply"]
                 try:
                     output = _applypatchhelper(shellcmd, patch, force, 
reverse, run)
                 except CmdError:
-- 
2.17.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#137131): 
https://lists.openembedded.org/g/openembedded-core/message/137131
Mute This Topic: https://lists.openembedded.org/mt/72890514/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub  
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to