Skip to content

Conversation

@racgoo
Copy link
Contributor

@racgoo racgoo commented Dec 28, 2025

Summary

  • Add 'worktree' feature with tests.

Changes

  • Implement worktree-like methods in 'Repository'
  • Add internal worktree features
  • Add test code

Closes #172

@racgoo racgoo requested a review from seokju-na as a code owner December 28, 2025 12:19
@vercel
Copy link

vercel bot commented Dec 28, 2025

@racgoo is attempting to deploy a commit to the Toss Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Dec 28, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
es-git Ready Ready Preview, Comment Jan 2, 2026 7:21am

src/worktree.rs Outdated
/// @param {Repository} repo - Repository to open worktree from.
/// @returns Worktree instance.
/// @throws Throws error if the repository is not a worktree or if opening fails.
pub fn open_from_repository(repo: Reference<Repository>, env: Env) -> crate::Result<Worktree> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we make this method as function?

Other constructor methods (e.g. openRepository, initRepository also use functions instead of static methods, so it would be good to unify interfaces.

Also, is colud be better if it were async.

e.g.

#[napi]
/// @signature
/// ```ts
/// function openWorktreeFromRepository(
///   repo: Repository,
/// ): Promise<Worktree>;
/// ```
pub fn open_worktree_from_repository(...) -> AsyncTask<WorktreeOpenFromRepositoryTask> {
  todo!()
}

Copy link
Contributor Author

@racgoo racgoo Dec 30, 2025

Choose a reason for hiding this comment

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

@seokju-na Sorry for the late reply. spent some time thinking through the async design here.

My current thinking is to use AsyncTask only when the operation can be
expressed in terms of pure Rust values (e.g. String, PathBuf, primitive
types) that can safely be moved to a worker thread.

In cases like this one, a real AsyncTask is not possible because
napi-managed objects cannot be moved to worker threads.

One alternative is a fake-async Promise-based API (sync execution +
immediate resolve), which would require upgrading napi-rs to >= 3.7.1.

For reference, the implementation would look like this

pub fn open_worktree_from_repository(repo: &Repository, env: Env) -> crate::Result<PromiseRaw<'_,Worktree>> {
  let git2_worktree = git2::Worktree::open_from_repository(&repo.inner);
  match git2_worktree {
    Ok(worktree) => {
      Ok(PromiseRaw::resolve(&env, Worktree { inner: worktree })?)
    },
    Err(error) => {
      Ok(PromiseRaw::reject(&env, error.to_string())?)
    }
  }
}

Does this approach sound reasonable to you?

racgoo and others added 3 commits December 29, 2025 11:33
Oh.. it's mistake

Co-authored-by: seokju-na <seokju.me@gmail.com>
I used '.map' here for brevity, even though it's not ideal for mutable side effects.
Thanks for the suggestion. I'll refactor this to an if let pattern.

Co-authored-by: seokju-na <seokju.me@gmail.com>
Same here. I’ll switch this to 'if let' for clarity. Thanks!

Co-authored-by: seokju-na <seokju.me@gmail.com>
@racgoo racgoo marked this pull request as draft December 29, 2025 02:41
@racgoo racgoo marked this pull request as ready for review December 30, 2025 08:39
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.

worktree

2 participants