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@xxxxxxx> --- 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