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

Re: What's cooking in git.git (Apr 2017, #02; draft as of Sat, 15)

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 17, 2017, 00:25 UTC
Message-ID
<xmqqtw5nlw2q.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<CACsJy8B08DN+0Kn-g6iV2JVkHej814tqXjFSx=XBhckDyGx5Vw@mail.gmail.com>
Duy Nguyen <pclouds@gmail.com> writes:
Show 8 quoted lines
>> * nd/worktree-add-lock (2017-04-15) 2 commits
>>  - SQUASH???
>>  - worktree add: add --lock option
>>
>
> Allow to lock a workktree immediately after it's created. This helps
> prevent a race between "git worktree add; git worktree lock" and "git
> worktree prune".

Thanks. Also thanks for "we at least need to ensure the lock file is there" comment, which led to this:

-- >8 --
From: Junio C Hamano <gitster@pobox.com>
Date: Sat, 15 Apr 2017 00:36:31 -0700
Subject: [PATCH] SQUASH???
---
 builtin/worktree.c      | 16 +++++++---------
 t/t2025-worktree-add.sh |  2 +-
 2 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 3dab07c829..5ebdcce793 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -243,7 +243,10 @@ static int add_worktree(const char *path, const char *refname,
 	 * after the preparation is over.
 	 */
 	strbuf_addf(&sb, "%s/locked", sb_repo.buf);
-	write_file(sb.buf, "initializing");
+	if (!opts->keep_locked)
+		write_file(sb.buf, "initializing");
+	else
+		write_file(sb.buf, "added with --lock");
 
 	strbuf_addf(&sb_git, "%s/.git", path);
 	if (safe_create_leading_directories_const(sb_git.buf))
@@ -306,15 +309,10 @@ static int add_worktree(const char *path, const char *refname,
 done:
 	strbuf_reset(&sb);
 	strbuf_addf(&sb, "%s/locked", sb_repo.buf);
-	if (!ret && opts->keep_locked) {
-		/*
-		 * Don't keep the confusing "initializing" message
-		 * after it's already over.
-		 */
-		truncate(sb.buf, 0);
-	} else {
+	if (!ret && opts->keep_locked)
+		;
+	else
 		unlink_or_warn(sb.buf);
-	}
 	argv_array_clear(&child_env);
 	strbuf_release(&sb);
 	strbuf_release(&symref);
diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh
index 6dce920c03..b5c47ac602 100755
--- a/t/t2025-worktree-add.sh
+++ b/t/t2025-worktree-add.sh
@@ -66,7 +66,7 @@ test_expect_success '"add" worktree' '
 test_expect_success '"add" worktree with lock' '
 	git rev-parse HEAD >expect &&
 	git worktree add --detach --lock here-with-lock master &&
-	test_must_be_empty .git/worktrees/here-with-lock/locked
+	test -f .git/worktrees/here-with-lock/locked
 '
 
 test_expect_success '"add" worktree from a subdir' '
-- 
2.12.2-820-g9f56312714
Previous: Duy Nguyen
Message 3 of 3 in “What's cooking in git.git (Apr 2017, #02; draft as of Sat, 15)”
  1. Junio C HamanoApr 15, 2017
  2. Duy NguyenApr 16, 2017
  3. Junio C HamanoApr 17, 2017

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.