提交 5cc8f372 编写于 作者: J Johannes Schindelin 提交者: Junio C Hamano

init: show "Reinit" message even in an (existing) empty repository

Earlier, git-init tested for a valid HEAD ref, but if the repository
was empty, there was none.  Instead, test for the existence of
the file $GIT_DIR/HEAD.
Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 76ce9462
......@@ -167,9 +167,9 @@ static int create_default_files(const char *git_dir, const char *template_path)
{
unsigned len = strlen(git_dir);
static char path[PATH_MAX];
unsigned char sha1[20];
struct stat st1;
char repo_version_string[10];
char junk[2];
int reinit;
int filemode;
......@@ -219,7 +219,8 @@ static int create_default_files(const char *git_dir, const char *template_path)
* branch, if it does not exist yet.
*/
strcpy(path + len, "HEAD");
reinit = !read_ref("HEAD", sha1);
reinit = (!access(path, R_OK)
|| readlink(path, junk, sizeof(junk)-1) != -1);
if (!reinit) {
if (create_symref("HEAD", "refs/heads/master", NULL) < 0)
exit(1);
......
......@@ -113,4 +113,21 @@ test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '
fi
'
test_expect_success 'reinit' '
(
unset GIT_CONFIG GIT_WORK_TREE GIT_CONFIG
mkdir again &&
cd again &&
git init >out1 2>err1 &&
git init >out2 2>err2
) &&
grep "Initialized empty" again/out1 &&
grep "Reinitialized existing" again/out2 &&
>again/empty &&
test_cmp again/empty again/err1 &&
test_cmp again/empty again/err2
'
test_done
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册