Skip to content

feat(packages/sui-mono): resolve git lock errors in commit-all when running from worktrees#1977

Open
paulusrex wants to merge 1 commit intomasterfrom
feat/enable-commit-all-worktrees
Open

feat(packages/sui-mono): resolve git lock errors in commit-all when running from worktrees#1977
paulusrex wants to merge 1 commit intomasterfrom
feat/enable-commit-all-worktrees

Conversation

@paulusrex
Copy link
Copy Markdown
Contributor

Description

sui-mono commit-all fails with index.lock errors when executed from a git worktree. The root cause is that git commands within the script use inconsistent working directories — git add runs with cwd set to the package subdirectory (relative path), while git status, git commit, and git reset inherit process.cwd() with no explicit cwd. In worktrees, this inconsistency causes git to fail when acquiring the index lock.

The fix resolves the repository root once at startup via git rev-parse --show-toplevel and passes it as an explicit cwd to all git commands, ensuring they all operate on the same git index. This works correctly in both regular repos and worktrees.

Related Issue

N/A

Example

Before (fails in worktrees):

  git worktree add ../my-feature -b my-feature
  cd ../my-feature
  sui-mono commit-all -t fix -m "some change"
  # => 
  cmd: 'git add .',
  stdout: '',
  stderr: "fatal: Unable to create '/Users/pablo.rey/workspace/code/adevinta-realestate/frontend-fc--web-server/.git/worktrees/tripoli/index.lock': File exists.\n" +
    '\n' +
    'Another git process seems to be running in this repository, e.g.\n' +
    "an editor opened by 'git commit'. Please make sure all processes\n" +
    'are terminated then try again. If it still fails, a git process\n' +
    'may have crashed in this repository earlier:\n' +
    'remove the file manually to continue.\n'

After (works in both regular repos and worktrees):

sui-mono commit-all -t fix -m "some change"
# => commits created successfully

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.

1 participant