Skip to content

Commit

Permalink
project.py: fix west diff --manifest to use manifest-rev
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
marc-hb committed Oct 11, 2024
1 parent 9b63d93 commit ff84d96
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/west/app/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ def do_add_parser(self, parser_adder):
parser.add_argument('-a', '--all', action='store_true',
help='include output for inactive projects')
parser.add_argument('-m', '--manifest', action='store_true',
help='show changes relative to the manifest revision')
help='show changes relative to "manifest-rev"')
return parser

def do_run(self, args, user_args):
Expand All @@ -800,9 +800,16 @@ def do_run(self, args, user_args):
# which it won't do ordinarily since stdout is not a terminal.
color = ['--color=always'] if self.color_ui else []
for project in self._cloned_projects(args, only_active=not args.all):
diff_commit = (
['manifest-rev'] # see #719 and #747
# Special-case the manifest repository while it's
# still showing up in the 'projects' list. Yet
# more evidence we should tackle #327.
if args.manifest and not isinstance(project, ManifestProject)
else []
)
# Use paths that are relative to the base directory to make it
# easier to see where the changes are
diff_commit = [project.revision] if args.manifest else []
cp = project.git(['diff', f'--src-prefix={project.path}/',
f'--dst-prefix={project.path}/',
'--exit-code'] + color + diff_commit,
Expand Down
1 change: 1 addition & 0 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ def test_diff(west_init_tmpdir):
cmd('update net-tools')
cmd('diff')
cmd('diff --stat')
cmd('diff --manifest')

cmd('update Kconfiglib')

Expand Down

0 comments on commit ff84d96

Please sign in to comment.