summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 76ce946)
raw | patch | inline | side by side (parent: 76ce946)
author | Johannes Schindelin <Johannes.Schindelin@gmx.de> | |
Mon, 24 Mar 2008 15:14:52 +0000 (16:14 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 25 Mar 2008 07:34:05 +0000 (00:34 -0700) |
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: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
was empty, there was none. Instead, test for the existence of
the file $GIT_DIR/HEAD.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-init-db.c | patch | blob | history | |
t/t0001-init.sh | patch | blob | history |
diff --git a/builtin-init-db.c b/builtin-init-db.c
index 79eaf8d6edf18675897f6eed571289fce450526a..2854868b4e4185d33024b9fe5d00ad631c18bb36 100644 (file)
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
{
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;
* 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);
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index c015405f124f738e66213987c3ba88c7d310caab..b0289e397ab683c8c5a02ce649d7790d6a876d16 100755 (executable)
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
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