Copilot commented on code in PR #3055:
URL: https://github.com/apache/dubbo-go/pull/3055#discussion_r2441769878


##########
Makefile:
##########
@@ -26,13 +26,14 @@ MAKEFLAGS += --no-print-directory
 CLI_DIR = tools/dubbogo-cli
 IMPORTS_FORMATTER_DIR = tools/imports-formatter
 
-.PHONY: help test fmt clean lint
+.PHONY: help test fmt clean lint check-fmt
 
 help:
        @echo "Available commands:"
        @echo "  test       - Run unit tests"
        @echo "  clean      - Clean test generate files"
        @echo "  fmt        - Format code"
+       @echo "  check-fmt  - Check code format using git status"

Review Comment:
   [nitpick] The description 'Check code format using git status' is unclear 
about what the command actually does. It should clarify that it verifies no 
uncommitted changes exist after formatting, such as 'Check that code is 
properly formatted (fails if uncommitted changes exist)'.
   ```suggestion
        @echo "  check-fmt  - Check that code is properly formatted (fails if 
uncommitted changes exist)"
   ```



##########
Makefile:
##########
@@ -46,6 +47,18 @@ fmt: install-imports-formatter
        go fmt ./... && GOROOT=$(shell go env GOROOT) imports-formatter
        cd $(CLI_DIR) && go fmt ./...
 
+# Check code format without modifying files (using git status)
+check-fmt:
+       @echo "Checking code format..."
+       @if [ -n "$$(git status --porcelain)" ]; then \
+               echo "Error: The following files have changes after 
formatting:"; \
+               echo "$$(git status --porcelain)"; \
+               echo ""; \
+               echo "Please run 'make fmt' to fix formatting issues and commit 
the changes."; \
+               exit 1; \
+       fi

Review Comment:
   The `check-fmt` command checks for any uncommitted changes in the 
repository, not just formatting-related changes. This will fail if there are 
unrelated uncommitted files in the working directory. Consider running `make 
fmt` first within this target, then checking for changes, or storing the git 
state before formatting and comparing after.
   ```suggestion
        @git diff --name-only > .git_fmt_before
        @$(MAKE) fmt
        @git diff --name-only > .git_fmt_after
        @diff_files=$$(comm -13 .git_fmt_before .git_fmt_after); \
        if [ -n "$$diff_files" ]; then \
                echo "Error: The following files have formatting changes:"; \
                echo "$$diff_files"; \
                echo ""; \
                echo "Please run 'make fmt' to fix formatting issues and commit 
the changes."; \
                rm -f .git_fmt_before .git_fmt_after; \
                exit 1; \
        fi
        @rm -f .git_fmt_before .git_fmt_after
   ```



-- 
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