From: Michal Suchanek <msuchanek@suse.de>
To: git@vger.kernel.org
Cc: Michal Suchanek <msuchanek@suse.de>
Subject: [PATCH 2/2] setup: don't fail if commondir is deleted.
Date: Fri, 15 Feb 2019 19:16:12 +0100 [thread overview]
Message-ID: <dd42ab7054077c7d29ad62e7481c00ab5c1bf864.1550254374.git.msuchanek@suse.de> (raw)
In-Reply-To: <429046b2c9f02c5e4f0af88db51f6c0c099f08a9.1550254374.git.msuchanek@suse.de>
When adding wotktrees git can die in get_common_dir_noenv while
examining existing worktrees because the commondir file does not exist.
Handle ENOENT so adding a worktree does not fail because of incompletely
set-up other worktree.
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
---
setup.c | 33 ++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/setup.c b/setup.c
index ca9e8a949ed8..7dec2e5589d9 100644
--- a/setup.c
+++ b/setup.c
@@ -274,22 +274,25 @@ int get_common_dir_noenv(struct strbuf *sb, const char *gitdir)
strbuf_addf(&path, "%s/commondir", gitdir);
if (file_exists(path.buf)) {
- if (strbuf_read_file(&data, path.buf, 0) <= 0)
- die_errno(_("failed to read %s"), path.buf);
- while (data.len && (data.buf[data.len - 1] == '\n' ||
- data.buf[data.len - 1] == '\r'))
- data.len--;
- data.buf[data.len] = '\0';
- strbuf_reset(&path);
- if (!is_absolute_path(data.buf))
- strbuf_addf(&path, "%s/", gitdir);
- strbuf_addbuf(&path, &data);
- strbuf_add_real_path(sb, path.buf);
- ret = 1;
- } else {
- strbuf_addstr(sb, gitdir);
+ if (strbuf_read_file(&data, path.buf, 0) <= 0) {
+ if (errno != ENOENT)
+ die_errno(_("failed to read %s"), path.buf);
+ } else {
+ while (data.len && (data.buf[data.len - 1] == '\n' ||
+ data.buf[data.len - 1] == '\r'))
+ data.len--;
+ data.buf[data.len] = '\0';
+ strbuf_reset(&path);
+ if (!is_absolute_path(data.buf))
+ strbuf_addf(&path, "%s/", gitdir);
+ strbuf_addbuf(&path, &data);
+ strbuf_add_real_path(sb, path.buf);
+ ret = 1;
+ goto out;
+ }
}
-
+ strbuf_addstr(sb, gitdir);
+out:
strbuf_release(&data);
strbuf_release(&path);
return ret;
--
2.20.1
next prev parent reply other threads:[~2019-02-15 18:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-15 18:16 [PATCH 1/2] worktree: fix worktree add race Michal Suchanek
2019-02-15 18:16 ` Michal Suchanek [this message]
2019-02-17 7:14 ` [PATCH 2/2] setup: don't fail if commondir is deleted Eric Sunshine
2019-02-18 8:54 ` Michal Suchánek
2019-02-15 18:59 ` [PATCH 1/2] worktree: fix worktree add race Junio C Hamano
2019-02-16 0:18 ` Michal Suchánek
2019-02-17 7:05 ` Eric Sunshine
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dd42ab7054077c7d29ad62e7481c00ab5c1bf864.1550254374.git.msuchanek@suse.de \
--to=msuchanek@suse.de \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).