<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
Hi Naushir<br>
<br>
Yes, I have hit this issue with pre-commit and your diagonsis is
right. <br>
<br>
<div class="moz-cite-prefix">On 1/20/21 4:29 PM, Naushir Patuck
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAEmqJPrFdj5AQvSMmmKhyR45MhUoV3v2DZYMMcgN2fAKO09=Fg@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div dir="ltr"><br>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Wed, 20 Jan 2021 at
10:52, Naushir Patuck <<a
href="mailto:naush@raspberrypi.com" moz-do-not-send="true">naush@raspberrypi.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<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>
</blockquote>
<div><br>
</div>
<div>Sorry, my git command has a typo above, it is
"git commit -a --fixup=xxxx"</div>
<div> <br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<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>
</blockquote>
</div>
</div>
</blockquote>
I think this will parse the HEAD commit and not the diff/staged
changes. I haven't looked at it closely but that's my understanding.
I have seen mostly using the hook as a post-commit by other devs and
that (in my testing) works fine. <br>
<blockquote type="cite"
cite="mid:CAEmqJPrFdj5AQvSMmmKhyR45MhUoV3v2DZYMMcgN2fAKO09=Fg@mail.gmail.com">
<div dir="ltr">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<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>
</blockquote>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
libcamera-devel mailing list
<a class="moz-txt-link-abbreviated" href="mailto:libcamera-devel@lists.libcamera.org">libcamera-devel@lists.libcamera.org</a>
<a class="moz-txt-link-freetext" href="https://lists.libcamera.org/listinfo/libcamera-devel">https://lists.libcamera.org/listinfo/libcamera-devel</a>
</pre>
</blockquote>
<br>
</body>
</html>