From patchwork Wed Jan 20 10:52:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 10911 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 41BFBBD808 for ; Wed, 20 Jan 2021 10:53:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BFFF16819A; Wed, 20 Jan 2021 11:53:05 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="fuwICoq4"; dkim-atps=neutral Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 27F896817D for ; Wed, 20 Jan 2021 11:53:04 +0100 (CET) Received: by mail-lj1-x22a.google.com with SMTP id x23so25485096lji.7 for ; Wed, 20 Jan 2021 02:53:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=mime-version:from:date:message-id:subject:to; bh=s2z+AxAv5SFSabwAfK9HauDfwPfAyziOrNuzJH7PHEE=; b=fuwICoq4HHKfjNvunwC7iDF/1yf/SwHKWJ8+ZnGvmDRAdneWSOuZJbCvkCWkTsey93 TgaV4XMxJ/Pr2nrPGyEETXJIaO7TR1q/qU0MWvjsuFl3MB0cNExpWeXh0129ZY6PXXag 67VXKgaSQmXlRqbcpRm9b7OltkhkkJRKPWvyo+8idRuGZxDGFeGarm3+TWpzgk+8scgV w8oVESJeUOjD3OPZnN3vL3fzHEjaCwf6MRx1xwPFY9s6qqX+wYmsU9ZSiR3VmYH39OOT cfhAJKhwEBjj99ZjAplkKuxIbMBSJD6iLX2rtawJY79TnBEjHXdZxZBgPIR0MHndmwYB 40LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=s2z+AxAv5SFSabwAfK9HauDfwPfAyziOrNuzJH7PHEE=; b=B+sVoQg3Hlfwef4kZAdI9l7Z9//UHSr5PeO7KxkKHRK1tNUkJ2ZD/cHm2AmkdGBe5r nywUddyCNlOSFZIXAxu61Bivibc/NSExKqzUkbY7dZjaqMqUVzccYQvqXwN1fNhsnRrx d6PYtC1liu9g3J7PitKF2SpZ3RbO6ltco1PKF43gT8QcFjhaPIyxsMxRGNkCaQptid68 vm/y4AnMAmT/5Tl5iY366HkdVX7eEqfRD9ZuLzvnN2aavbTHkLIr8Wuul4RS5rgnFskt UmGqL1wMX47HOxJrsGOexU06Z7/UnAPflYMGTyXupEvfxr3y4RjA37/5taTY2REaeZ2e gi1g== X-Gm-Message-State: AOAM531wX8rHn6KBCbFSKMhrVfB9Whe++6uIvcKeKgvQ3889P9v+NpHg bLKIf98yrRXIslW6j2RnM7W/g0TQ/ETdKD5T60AztNdv8qS2NA== X-Google-Smtp-Source: ABdhPJymaSI2U0bCNlleyHiK57gHx+amthCP+JS5mU4bl0Ptekyn4bfO7UOoKzDWmJta0R+yvGPYaxwR9xSuBnw1QNI= X-Received: by 2002:a2e:93d6:: with SMTP id p22mr4276523ljh.169.1611139983279; Wed, 20 Jan 2021 02:53:03 -0800 (PST) MIME-Version: 1.0 From: Naushir Patuck Date: Wed, 20 Jan 2021 10:52:47 +0000 Message-ID: To: libcamera devel Subject: [libcamera-devel] Problem with utils/checkstyle.py in a pre-commit hook? X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 [...] -- [...]' Traceback (most recent call last): File "./utils/checkstyle.py", line 875, in 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: 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 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()