Skip to content

locking: ignore missing files after unlock - #6244

Merged
chrisd8088 merged 3 commits into
git-lfs:mainfrom
lawrence3699:fix/unlock-json-missing-file
Apr 23, 2026
Merged

chrisd8088 merged 3 commits into
git-lfs:mainfrom
lawrence3699:fix/unlock-json-missing-file

Conversation

@lawrence3699

Copy link
Copy Markdown
Contributor

Fixes #6167

When one clone has the lockable pattern but not the newly locked file, git lfs unlock --json <path> can remove the server lock and then turn that successful unlock into a local failure while trying to make the missing path read-only.

Before this change, the unlock POST succeeded but the command exited with unlocked:false and a local stat ... no such file or directory reason.

After this change, a successful unlock stays successful, and the post-unlock chmod step is skipped when the file is not present in the current worktree.

I also added a regression in t/t-unlock.sh that reproduces the two-clone lockable-pattern case from the issue.

Validation:

  • make -C t t-unlock.sh
  • go test ./locking

@lawrence3699
lawrence3699 requested a review from a team as a code owner April 17, 2026 15:16
Copilot AI review requested due to automatic review settings April 17, 2026 15:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes an inconsistency where git lfs unlock --json <path> could successfully remove a server lock but still report "unlocked": false due to a local chmod/stat failure when the target file didn’t exist in the current worktree (notably in multi-clone scenarios with lockable patterns).

Changes:

  • Skip the post-unlock “make read-only” chmod step when the unlocked path does not exist locally.
  • Add a regression test covering the “two clones + lockable pattern + missing file in the unlocking clone” scenario.
  • Preserve successful unlock reporting in --json output when the server unlock succeeds.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
locking/locks.go Avoids failing a successful unlock due to attempting to chmod a missing local file.
t/t-unlock.sh Adds regression coverage for unlocking a lockable file that’s missing from the current clone’s worktree.

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

@chrisd8088 chrisd8088 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks so much for this helpful bug fix and for including a comprehensive test!

I made some suggestions regarding the test, but only to try to simplify its setup steps and add a check of the exit code from the git lfs unlock command. Please let me know what you think of those, and thanks again for this PR!

Comment thread t/t-unlock.sh Outdated
@chrisd8088 chrisd8088 mentioned this pull request Apr 23, 2026
In a prior commit in this PR we resolved the issue reported in git-lfs#6167
so that the "git lfs unlock" command no longer reports an error if
the --json option is specified and the command is used to unlock an
extant lock for a file which does not exist in the current working
directory.

At the same time, we also added a new "unlocking a missing lockable
file (--json)" test to our "t/t-unlock.sh" shell test script to verify
that the changes we made are effective.  At present, this test is
based on the reproduction steps from git-lfs#6167 and so it creates a test
repository and then clones the repository twice, using one clone to
lock a local file and one clone to try to unlock the file even though
it does not exist in the second clone.

As discussed in PR review, we can simplify this new test because
we can create the necessary test conditions in a single repository
just by deleting the locked file after creating the lock:

  git-lfs#6244 (review)

We do, though, add a check that the "git lfs pull" command returns
a zero exit code, which our test would not otherwise validate because
we run the command in a pipeline, and the exit code from the pipeline
will be that of the tee(1) command.

@chrisd8088 chrisd8088 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks again for fixing this bug!

@chrisd8088
chrisd8088 merged commit e09c0f6 into git-lfs:main Apr 23, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unlock --json reporting of non-existant file

3 participants

Sponsor
SponsoredKunjungi sekarang
Promo