Skip to content

Commit ff84d96

Browse files
committed
project.py: fix west diff --manifest to use manifest-rev
Fixes new `west diff --manifest` option added by commit 0d5ee4e ("app: project: Allow to diff against manifest revision") Do not pass `project.revision` to `git diff` because `project.revision` is unresolved user input and does not always resolve to a commit. For instance, `project.revision` can be the name of a remote branch like `v3.7-branch` that does not exist locally; then `git diff` fails. Or even worse: there could be a local branch of the same name which points to a totally different commit. This bug was found when discussing issue #747, see 7th comment there for a longer description of what `manifest-rev` is and how it works. Signed-off-by: Marc Herbert <[email protected]>
1 parent 9b63d93 commit ff84d96

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/west/app/project.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ def do_add_parser(self, parser_adder):
788788
parser.add_argument('-a', '--all', action='store_true',
789789
help='include output for inactive projects')
790790
parser.add_argument('-m', '--manifest', action='store_true',
791-
help='show changes relative to the manifest revision')
791+
help='show changes relative to "manifest-rev"')
792792
return parser
793793

794794
def do_run(self, args, user_args):
@@ -800,9 +800,16 @@ def do_run(self, args, user_args):
800800
# which it won't do ordinarily since stdout is not a terminal.
801801
color = ['--color=always'] if self.color_ui else []
802802
for project in self._cloned_projects(args, only_active=not args.all):
803+
diff_commit = (
804+
['manifest-rev'] # see #719 and #747
805+
# Special-case the manifest repository while it's
806+
# still showing up in the 'projects' list. Yet
807+
# more evidence we should tackle #327.
808+
if args.manifest and not isinstance(project, ManifestProject)
809+
else []
810+
)
803811
# Use paths that are relative to the base directory to make it
804812
# easier to see where the changes are
805-
diff_commit = [project.revision] if args.manifest else []
806813
cp = project.git(['diff', f'--src-prefix={project.path}/',
807814
f'--dst-prefix={project.path}/',
808815
'--exit-code'] + color + diff_commit,

tests/test_project.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ def test_diff(west_init_tmpdir):
350350
cmd('update net-tools')
351351
cmd('diff')
352352
cmd('diff --stat')
353+
cmd('diff --manifest')
353354

354355
cmd('update Kconfiglib')
355356

0 commit comments

Comments
 (0)