gemini-code-assist[bot] commented on code in PR #18864:
URL: https://github.com/apache/tvm/pull/18864#discussion_r2872943469


##########
tests/lint/check_asf_header.py:
##########
@@ -216,17 +216,29 @@ def should_skip_file(filepath: str) -> bool:
 
 
 def get_git_files() -> list[str] | None:
-    """Get list of files tracked by git."""
+    """Get list of files tracked by git (excluding files staged for 
deletion)."""
     try:
         result = subprocess.run(
             ["git", "ls-files"], check=False, capture_output=True, text=True, 
cwd=Path.cwd()
         )
-        if result.returncode == 0:
-            return [line.strip() for line in result.stdout.split("\n") if 
line.strip()]
-        else:
+        if result.returncode != 0:
             print("Error: Could not get git files. Make sure you're in a git 
repository.")
             print("Git command failed:", result.stderr.strip())
             return None
+        all_files = {line.strip() for line in result.stdout.split("\n") if 
line.strip()}
+        # Exclude files staged for deletion so the header check does not
+        # report errors for files that are intentionally being removed.
+        deleted_result = subprocess.run(
+            ["git", "ls-files", "--deleted"],
+            check=False,
+            capture_output=True,
+            text=True,
+            cwd=Path.cwd(),
+        )
+        if deleted_result.returncode == 0:
+            deleted = {line.strip() for line in 
deleted_result.stdout.split("\n") if line.strip()}
+            all_files -= deleted

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The error handling for the `git ls-files --deleted` command could be 
improved. If the command fails (i.e., `returncode != 0`), it currently fails 
silently. It would be better to print a warning to the console, similar to how 
a failure of the main `git ls-files` command is handled. This would make the 
script more robust and easier to debug when something goes wrong.
   
   Consider adding an `elif` block to handle this case:
   ```python
   if deleted_result.returncode == 0:
       deleted = {line.strip() for line in deleted_result.stdout.split("\n") if 
line.strip()}
       all_files -= deleted
   elif deleted_result.stderr:
       print(f"Warning: 'git ls-files --deleted' failed: 
{deleted_result.stderr.strip()}")
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to