nodes: 0, module; 1, function_definition; 2, function_name:git_hook; 3, parameters; 4, block; 5, default_parameter; 6, expression_statement; 7, comment:# Get list of files modified and staged; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, for_statement; 12, return_statement; 13, identifier:strict; 14, False; 15, comment:"""
      Git pre-commit hook to check staged files for isort errors
  
      :param bool strict - if True, return number of errors on exit,
          causing the hook to fail. If False, return zero so it will
          just act as a warning.
  
      :return number of errors if in strict mode, 0 otherwise.
      """; 16, assignment; 17, assignment; 18, assignment; 19, identifier:filename; 20, identifier:files_modified; 21, block; 22, conditional_expression:errors if strict else 0; 23, identifier:diff_cmd; 24, string:"git diff-index --cached --name-only --diff-filter=ACMRTUXB HEAD"; 25, identifier:files_modified; 26, call; 27, identifier:errors; 28, integer:0; 29, if_statement; 30, identifier:errors; 31, identifier:strict; 32, integer:0; 33, identifier:get_lines; 34, argument_list; 35, call; 36, comment:# Get the staged contents of the file; 37, block; 38, identifier:diff_cmd; 39, attribute; 40, argument_list; 41, expression_statement; 42, expression_statement; 43, expression_statement; 44, if_statement; 45, identifier:filename; 46, identifier:endswith; 47, string; 48, assignment; 49, assignment; 50, assignment; 51, attribute; 52, block; 53, string_content:.py; 54, identifier:staged_cmd; 55, binary_operator:"git show :%s" % filename; 56, identifier:staged_contents; 57, call; 58, identifier:sort; 59, call; 60, identifier:sort; 61, identifier:incorrectly_sorted; 62, expression_statement; 63, string:"git show :%s"; 64, identifier:filename; 65, identifier:get_output; 66, argument_list; 67, identifier:SortImports; 68, argument_list; 69, augmented_assignment; 70, identifier:staged_cmd; 71, keyword_argument; 72, keyword_argument; 73, keyword_argument; 74, identifier:errors; 75, integer:1; 76, identifier:file_path; 77, identifier:filename; 78, identifier:file_contents; 79, call; 80, identifier:check; 81, True; 82, attribute; 83, argument_list; 84, identifier:staged_contents; 85, identifier:decode
code: def git_hook(strict=False):
      """
      Git pre-commit hook to check staged files for isort errors
  
      :param bool strict - if True, return number of errors on exit,
          causing the hook to fail. If False, return zero so it will
          just act as a warning.
  
      :return number of errors if in strict mode, 0 otherwise.
      """
  
      # Get list of files modified and staged
      diff_cmd = "git diff-index --cached --name-only --diff-filter=ACMRTUXB HEAD"
      files_modified = get_lines(diff_cmd)
  
      errors = 0
      for filename in files_modified:
          if filename.endswith('.py'):
              # Get the staged contents of the file
              staged_cmd = "git show :%s" % filename
              staged_contents = get_output(staged_cmd)
  
              sort = SortImports(
                  file_path=filename,
                  file_contents=staged_contents.decode(),
                  check=True
              )
  
              if sort.incorrectly_sorted:
                  errors += 1
  
      return errors if strict else 0