From: Junio C Hamano <gitster@pobox•com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail•com>
Cc: git@vger•kernel.org, David.Taylor@dell•com
Subject: Re: [PATCH] worktree add: add --lock option
Date: Sat, 15 Apr 2017 01:07:13 -0700 [thread overview]
Message-ID: <xmqqmvbim6vi.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <xmqqzifim8co.fsf@gitster.mtv.corp.google.com> (Junio C. Hamano's message of "Sat, 15 Apr 2017 00:35:19 -0700")
Junio C Hamano <gitster@pobox•com> writes:
> Nguyễn Thái Ngọc Duy <pclouds@gmail•com> writes:
>
>> - unlink_or_warn(sb.buf);
>> + if (!ret && opts->keep_locked) {
>> + /*
>> + * Don't keep the confusing "initializing" message
>> + * after it's already over.
>> + */
>> + truncate(sb.buf, 0);
>> + } else {
>> + unlink_or_warn(sb.buf);
>> + }
>
> builtin/worktree.c: In function 'add_worktree':
> builtin/worktree.c:314:11: error: ignoring return value of 'truncate', declared with attribute warn_unused_result [-Werror=unused-result]
> truncate(sb.buf, 0);
> ^
> cc1: all warnings being treated as errors
> make: *** [builtin/worktree.o] Error 1
I wonder why we need to have "initializing" and then remove the
string. Wouldn't it be simpler to do something like this instead?
Does an empty lockfile have some special meaning?
builtin/worktree.c | 16 +++++++---------
t/t2025-worktree-add.sh | 3 +--
2 files changed, 8 insertions(+), 11 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..304f25fcd1 100755
--- a/t/t2025-worktree-add.sh
+++ b/t/t2025-worktree-add.sh
@@ -65,8 +65,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
+ git worktree add --detach --lock here-with-lock master
'
test_expect_success '"add" worktree from a subdir' '
next prev parent reply other threads:[~2017-04-15 8:07 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-11 15:14 git work trees taylor, david
2017-04-12 13:36 ` Duy Nguyen
2017-04-12 13:58 ` [PATCH] worktree add: add --lock option Nguyễn Thái Ngọc Duy
2017-04-13 22:50 ` Junio C Hamano
2017-04-14 13:00 ` Duy Nguyen
2017-04-24 14:06 ` taylor, david
2017-04-14 16:27 ` Jacob Keller
2017-04-15 7:35 ` Junio C Hamano
2017-04-15 8:07 ` Junio C Hamano [this message]
2017-04-15 11:34 ` Duy Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqmvbim6vi.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox$(echo .)com \
--cc=David.Taylor@dell$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=pclouds@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox