<div dir="ltr">Hi all,<div><br></div><div>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:</div><div><br></div><div>fatal: ambiguous argument '': unknown revision or path not in the working tree.<br>Use '--' to separate paths from revisions, like this:<br>'git <command> [<revision>...] -- [<file>...]'<br>Traceback (most recent call last):<br>  File "./utils/checkstyle.py", line 875, in <module><br>    sys.exit(main(sys.argv))<br>  File "./utils/checkstyle.py", line 850, in main<br>    commits.append(StagedChanges())<br>  File "./utils/checkstyle.py", line 237, in __init__<br>    Commit.__init__(self, '')<br>  File "./utils/checkstyle.py", line 206, in __init__<br>    self.__parse()<br>  File "./utils/checkstyle.py", line 215, in __parse<br>    self.__title = files[0]<br>IndexError: list index out of range<br></div><div><br></div><div>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:</div><div><br></div><div>ret = subprocess.run(['git', 'show', '--pretty=oneline', '--name-status',<br>                                  self.commit],<br>                                  stdout=subprocess.PIPE).stdout.decode('utf-8')<br></div><div><br></div><div>where self.commit is an empty string.</div><div><br></div><div>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:</div><div><br></div><div>diff --git a/utils/checkstyle.py b/utils/checkstyle.py<br>index 0e9659e98518..cb7b2d151412 100755<br>--- a/utils/checkstyle.py<br>+++ b/utils/checkstyle.py<br>@@ -207,9 +207,11 @@ class Commit:<br> <br>     def __parse(self):<br>         # Get the commit title and list of files.<br>-        ret = subprocess.run(['git', 'show', '--pretty=oneline', '--name-status',<br>-                              self.commit],<br>-                             stdout=subprocess.PIPE).stdout.decode('utf-8')<br>+        args = ['git', 'show', '--pretty=oneline', '--name-status']<br>+        if self.commit != '':<br>+            args.append(self.commit)<br>+<br>+        ret = subprocess.run(args, stdout=subprocess.PIPE).stdout.decode('utf-8')<br>         files = ret.splitlines()<br>         self.__files = [CommitFile(f) for f in files[1:]]<br></div><div><br></div><div>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?</div><div><br></div><div>Regards,</div><div>Naush</div><div><br></div></div>