Skip to content

feat: add jujutsu walker #601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 21, 2025
Merged

Conversation

delafthi
Copy link
Contributor

@delafthi delafthi commented Jun 19, 2025

This PR introduces a new Jujutsu walker to numtide/treefmt, modeled after the existing Git walker but tailored to Jujutsu repositories. Key differences include:

  • The list command does not update the index automatically, so untracked files must be explicitly added via jj commands.

This addition enables proper handling of Jujutsu ignore rules without requiring co-located Git repos, improving integration and file traversal accuracy for Jujutsu users.

I lack Go experience and primarily copied, and adapted the existing Git walker by adjusting commands. I would welcome guidance or collaboration to develop a more idiomatic and robust implementation.

@delafthi delafthi changed the title feat(walk): add method to walk the filesystem with jujutsu feat: add jujutsu walker Jun 19, 2025
@delafthi delafthi force-pushed the push-rtxoonqmxkxy branch 2 times, most recently from 2dd1b91 to 60b2c48 Compare June 19, 2025 14:26
@delafthi
Copy link
Contributor Author

Jujutsu tests in cmd/root_test.go still fail. Needs investigation.

@delafthi delafthi force-pushed the push-rtxoonqmxkxy branch 8 times, most recently from 84f58f0 to c6d51bc Compare June 21, 2025 21:36
Copy link
Collaborator

@jfly jfly left a comment

Choose a reason for hiding this comment

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

The approach here looks good to me.

In the future, it could make sense to create some abstraction over git and jj, but IMO that's not warranted here. Copying and tweaking is good, and the tests you're adding are super valuable if we ever feel the need to do a future refactor.

@@ -329,6 +330,21 @@ func determineTreeRoot(v *viper.Viper, cfg *Config, logger *log.Logger) error {
}
}

// attempt to resolve with jujutsu
Copy link
Collaborator

Choose a reason for hiding this comment

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

If walk == auto, do we first attempt to resolve with git, and then attempt to resolve with jujutsu? That feels silly to me: we should not keep searching after we find a tree route. In other words, guard this with cfg.TreeRoot == "" (as we do below).

I suspect there's a flatter refactor of all this that looks less like the current case with a big default block and is instead:

  1. if no tree root, search with tree root file
  2. if (still) no tree root, search with tree root cmd
  3. if (still) no tree root (and walk is auto or git), search with git
  4. if (still) no tree root (and walk is auto or jujutsu), search with jujutsu
  5. if (still) no tree root, use the directory containing the config file

If you do opt to make this refactor, please split it into a separate initial commit that we could merge first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, I added cfg.TreeRoot == "" as a guard:

if cfg.TreeRoot == "" && (cfg.Walk == walk.Auto.String() || cfg.Walk == walk.Jujutsu.String()) {
  logger.Infof("attempting to resolve tree root using jujutsu: %s", jujutsu.TreeRootCmd)
  ...

@delafthi delafthi force-pushed the push-rtxoonqmxkxy branch 2 times, most recently from 1f31b83 to 4b4c4f5 Compare July 5, 2025 13:30
- added jujutsu module similar to the git module, which provides the `IsInsideWorktree` function
- added jujutsu walker, with the following differences to the git walker
  - the list command does not update the index. thus, new files are not listed, the user has to add them to the index first by running a `jj` command
- added jujutsu walker test
- added jujutsu walker root test
- adapted config and docs
@delafthi delafthi force-pushed the push-rtxoonqmxkxy branch from 4b4c4f5 to de5d307 Compare July 5, 2025 13:39
@delafthi
Copy link
Contributor Author

delafthi commented Jul 5, 2025

Additionally, I rebase unto latest main to fix the failing tests in TestGit (cmd/root_test.go).

@delafthi
Copy link
Contributor Author

delafthi commented Jul 5, 2025

I'm not sure why the current tests are failing. The difference is always one file that gets additionally formatted. Also, I get the exact same result when building on aarch64-darwin. However, on aarch64-linux treefmt builds successfully, passing all tests.

@delafthi delafthi marked this pull request as ready for review July 5, 2025 14:26
Removed unnecessary unquoting logic for lines (file paths) starting with a quote.
@delafthi delafthi force-pushed the push-rtxoonqmxkxy branch from 811c171 to 6cfbdf0 Compare July 5, 2025 22:23
@brianmcgee
Copy link
Member

brianmcgee commented Jul 7, 2025

@delafthi I think what you're seeing is a brittle test. I've been seeing it periodically and trying to get to the bottom of it with no joy 😞

I'll try to find some time to review this week.

@brianmcgee
Copy link
Member

@Enzime can you give this a review since I'm really not familiar with jujutsu

@brianmcgee brianmcgee merged commit b33ed00 into numtide:main Jul 21, 2025
27 checks passed
@delafthi delafthi deleted the push-rtxoonqmxkxy branch July 21, 2025 22:51
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