[libcamera-devel] Problem with utils/checkstyle.py in a pre-commit hook?
Naushir Patuck
naush at raspberrypi.com
Wed Jan 20 11:52:47 CET 2021
Hi all,
I have started noticing a problem with the utils/checkstyle.py script when
run in the provided pre-commit hook (utils/hooks/pre-commit). Here is an
example output when I do a "git commit --amend --fixup=xxxx" command:
fatal: ambiguous argument '': unknown revision or path not in the working
tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Traceback (most recent call last):
File "./utils/checkstyle.py", line 875, in <module>
sys.exit(main(sys.argv))
File "./utils/checkstyle.py", line 850, in main
commits.append(StagedChanges())
File "./utils/checkstyle.py", line 237, in __init__
Commit.__init__(self, '')
File "./utils/checkstyle.py", line 206, in __init__
self.__parse()
File "./utils/checkstyle.py", line 215, in __parse
self.__title = files[0]
IndexError: list index out of range
This used to certainly work in the past, so I can only assume either
something in the script, or my environment has changed. The reason behind
the git command failure seems to be related to the last argument in the
subprocess call:
ret = subprocess.run(['git', 'show', '--pretty=oneline', '--name-status',
self.commit],
stdout=subprocess.PIPE).stdout.decode('utf-8')
where self.commit is an empty string.
This may have been introduced by commit 097720840 ('utils: checkstyle.py:
Move commit handling to a separate section'). A fix that works for me is
as follows:
diff --git a/utils/checkstyle.py b/utils/checkstyle.py
index 0e9659e98518..cb7b2d151412 100755
--- a/utils/checkstyle.py
+++ b/utils/checkstyle.py
@@ -207,9 +207,11 @@ class Commit:
def __parse(self):
# Get the commit title and list of files.
- ret = subprocess.run(['git', 'show', '--pretty=oneline',
'--name-status',
- self.commit],
- stdout=subprocess.PIPE).stdout.decode('utf-8')
+ args = ['git', 'show', '--pretty=oneline', '--name-status']
+ if self.commit != '':
+ args.append(self.commit)
+
+ ret = subprocess.run(args,
stdout=subprocess.PIPE).stdout.decode('utf-8')
files = ret.splitlines()
self.__files = [CommitFile(f) for f in files[1:]]
I was just wondering if I have something strange in my environment that is
causing these issues, or are other folks seeing this as well?
Regards,
Naush
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20210120/89050d85/attachment.htm>
More information about the libcamera-devel
mailing list