repository.get_submodules: Only strip repo path from the beginning
authorDoesnot Matter <you@example.com>
Thu, 26 May 2022 16:20:39 +0000 (18:20 +0200)
committerDoesnot Matter <you@example.com>
Thu, 26 May 2022 17:29:38 +0000 (19:29 +0200)
We shouldn't just replace any occurence since we otherwise might also
substitute in the submodule.

Based on a patch by "ushen <yshxxsjt715@gmail.com>".
See https://github.com/agx/git-buildpackage/pull/82

gbp/git/repository.py

index 012268048e30bc200e4ccd30530aee0cd6fabb1f..4d11fae6886fef996c724c2184e97b63a9a68259 100644 (file)
@@ -1984,8 +1984,9 @@ class GitRepository(object):
             # A submodules is shown as "commit" object in ls-tree:
             if objtype == "commit":
                 nextpath = os.path.join(path, name)
-                submodules.append((nextpath.replace(self.path, '').lstrip('/'),
-                                   commit))
+                if nextpath.startswith(self.path):
+                    nextpath = nextpath[len(self.path):].lstrip('/')
+                submodules.append((nextpath, commit))
                 if recursive:
                     submodules += self.get_submodules(commit, path=nextpath,
                                                       recursive=recursive)