Skip to content

feat(cmd/gf): improve gf run watching#4573

Merged
hailaz merged 12 commits intomasterfrom
feat/gfrun
Dec 26, 2025
Merged

feat(cmd/gf): improve gf run watching#4573
hailaz merged 12 commits intomasterfrom
feat/gfrun

Conversation

@hailaz
Copy link
Contributor

@hailaz hailaz commented Dec 25, 2025

This pull request introduces a significant enhancement to the gf run command, focusing on improving the directory watching mechanism for hot-reload functionality. The main improvements include a more intelligent and efficient algorithm for determining which directories to watch (recursively or non-recursively), support for custom ignore patterns, and a comprehensive set of unit tests to ensure correctness. Additionally, some outdated database drivers were removed from the dependencies.

Key changes:

Directory Watching Improvements

  • Refactored the directory watching logic in cmd_run.go to use a DFS-based algorithm that minimizes the number of watched directories while respecting ignored patterns. Directories and their descendants without ignored subdirectories are watched recursively; otherwise, non-recursive watches are set, and valid children are recursed into. This results in more efficient and accurate hot-reload behavior. (cmd/gf/internal/cmd/cmd_run.go)
  • Added support for custom ignore patterns via the new -i/--ignorePatterns flag, allowing users to specify directories to be excluded from watching. Default ignored patterns include node_modules, vendor, hidden directories, and directories starting with an underscore. (cmd/gf/internal/cmd/cmd_run.go) [1] [2] [3]
  • Improved parsing of comma-separated arguments for both watch paths and ignore patterns to support flexible CLI usage. (cmd/gf/internal/cmd/cmd_run.go)

User Experience and Documentation

  • Updated help messages, usage examples, and documentation to reflect the new features and more intuitive CLI options for specifying watch paths and ignore patterns. (cmd/gf/internal/cmd/cmd_run.go) [1] [2]

Testing

  • Added a comprehensive unit test suite for the new getWatchPaths logic, covering various scenarios including custom ignore patterns, deeply nested structures, multiple roots, non-existent directories, and edge cases. (cmd/gf/internal/cmd/cmd_z_unit_run_test.go)

Dependency Cleanup

  • Removed unused database driver dependencies from go.mod to streamline the project dependencies. (cmd/gf/go.mod)

These changes collectively make the hot-reload feature more robust, configurable, and efficient, while ensuring maintainability through thorough testing.

Copilot AI review requested due to automatic review settings December 25, 2025 04:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request enhances the gf run command by adding support for custom ignore patterns during directory watching for live reload. It introduces a new -i/--ignorePatterns CLI flag, refactors the directory watching logic to use a breadth-first search algorithm for determining which directories to monitor, and adds unit tests to verify the new functionality.

Key changes:

  • Adds customizable ignore patterns via the -i/--ignorePatterns flag with corresponding struct field and CLI integration
  • Replaces flat directory watching with a BFS-based algorithm (getWatchPaths) that intelligently determines the minimal set of directories to watch while respecting ignore patterns
  • Includes helper functions (hasIgnoredDescendant, isIgnoredDirName) and default ignore patterns for common non-source directories like .git, node_modules, and vendor

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
cmd/gf/internal/cmd/testdata/fix/fix25_content.go Removes unused imports (fmt, time, gtest) from test data file
cmd/gf/internal/cmd/cmd_z_unit_run_test.go Adds unit tests for getWatchPaths method covering basic functionality, empty watch paths, and custom ignore patterns
cmd/gf/internal/cmd/cmd_run.go Main implementation: adds IgnorePatterns field to cRunApp struct, registers new CLI flag, implements BFS-based directory watching algorithm with helper functions, and updates command documentation/examples

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hailaz hailaz requested a review from houseme December 26, 2025 06:06
@hailaz hailaz merged commit c82da1e into master Dec 26, 2025
20 checks passed
@hailaz hailaz deleted the feat/gfrun branch December 26, 2025 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants