git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git update-index not delete lock file when using different worktree

From
Duy Nguyen <pclouds@gmail.com>
Date
Jul 17, 2014, 10:36 UTC
Message-ID
<20140717103654.GA18897@lanh>
In-Reply-To
<1405585628972-7615306.post@n2.nabble.com>
On Thu, Jul 17, 2014 at 01:27:08AM -0700, Yue Lin Ho wrote:
Show 7 quoted lines
> I see that refresh() of update_index.c calls setup_work_tree() to change dir
> to working tree.
> And the dir is not changed back to git dir before commit_lock_file() or
> rollback_lock_file() is called.
> 
> So, commit_lock_file() rename file failed.
> or rollback_lock_file() delete file failed.

I think you're on the right track. Although the problem is hold_locked_index() in cmd_update_index() when the index path is relative. After setup_work_tree(), the saved path points to a wrong place and can't be unlinked anymore.

This patch seems to fix it
-- 8< --
diff --git a/lockfile.c b/lockfile.c
index 2a800ce..69fe837 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -264,7 +264,8 @@ int commit_lock_file(struct lock_file *lk)
 
 int hold_locked_index(struct lock_file *lk, int die_on_error)
 {
-	return hold_lock_file_for_update(lk, get_index_file(),
+	return hold_lock_file_for_update(lk,
+					 absolute_path(get_index_file()),
 					 die_on_error
 					 ? LOCK_DIE_ON_ERROR
 					 : 0);
-- 8< --

We could turn all lockfile's path absolute when setup_work_tree()
moves pwd, but that seems dangerous without looking through how all
lockfiles are used.

--
Duy
Previous: Yue Lin HoNext: Yue Lin Ho
Message 3 of 4 in “git update-index not delete lock file when using different worktree”
  1. Yue Lin HoJul 17, 2014
  2. Yue Lin HoJul 17, 2014
  3. Duy NguyenJul 17, 2014
  4. Yue Lin HoJul 18, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.