Fix generating patches of independent packages in a single repo

This commit is contained in:
Michal Sojka 2024-12-28 16:36:07 +01:00
parent c06d6087d3
commit 9406815aba
2 changed files with 17 additions and 1 deletions

View file

@ -450,7 +450,7 @@ def ros2nix(args):
if args.patches:
patches = subprocess.check_output(
f"if ! git diff --quiet {upstream_rev}..HEAD -- .; then git format-patch --relative {upstream_rev}..HEAD; fi",
f"for i in $(git rev-list --reverse --relative {upstream_rev}..HEAD -- .); do git format-patch --zero-commit --relative -1 $i; done",
shell=True, cwd=srcdir,
).decode().strip().splitlines()
elif head != upstream_rev:

View file

@ -97,3 +97,19 @@ load common.bash
assert_failure
assert_line --partial "Patch ./0001-test-patch.patch already exists"
}
@test "--fetch --patches with two changes, each for different package " {
git clone https://github.com/wentasah/ros2nix
pushd ros2nix
sed -i -e 's/hello world/hello patch/' test/ws/src/ros_node/src/node.cpp
git commit -m 'node patch' -- test/ws/src/ros_node/src/node.cpp
sed -i -e '1a// comment' test/ws/src/library/src/library.cpp
git commit -m 'library patch' -- test/ws/src/library/src/library.cpp
popd
ros2nix --output-as-nix-pkg-name --fetch --patches $(find "ros2nix/test/ws/src" -name package.xml)
assert_file_contains ./library.nix library-patch\.patch
assert_file_contains ./ros-node.nix node-patch\.patch
assert_file_not_contains ./library.nix node-patch\.patch
assert_file_not_contains ./ros-node.nix library-patch\.patch
nix-build -A rosPackages.jazzy.ros-node
}