Commit e350ead34f47da102e6936f902c68f38131d315a

Stefan Sperling 2018-03-11T12:23:28

create an emtpy base-commit file

diff --git a/lib/got_worktree_priv.h b/lib/got_worktree_priv.h
index 621a020..3d62098 100644
--- a/lib/got_worktree_priv.h
+++ b/lib/got_worktree_priv.h
@@ -36,6 +36,7 @@ struct got_worktree {
 #define GOT_WORKTREE_FILE_INDEX		"fileindex"
 #define GOT_WORKTREE_REPOSITORY		"repository"
 #define GOT_WORKTREE_PATH_PREFIX	"path-prefix"
+#define GOT_WORKTREE_BASE_COMMIT	"base-commit"
 #define GOT_WORKTREE_LOCK		"lock"
 #define GOT_WORKTREE_FORMAT		"format"
 
diff --git a/lib/worktree.c b/lib/worktree.c
index cdfcd00..d4385a5 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -173,6 +173,11 @@ got_worktree_init(const char *path, struct got_reference *head_ref,
 	if (err)
 		goto done;
 
+	/* Create an empty base commit file. */
+	err = create_meta_file(gotpath, GOT_WORKTREE_BASE_COMMIT, NULL);
+	if (err)
+		goto done;
+
 	/* Write the HEAD reference. */
 	refstr = got_ref_to_str(head_ref);
 	if (refstr == NULL) {
diff --git a/regress/worktree/worktree_test.c b/regress/worktree/worktree_test.c
index 280103e..fc19621 100644
--- a/regress/worktree/worktree_test.c
+++ b/regress/worktree/worktree_test.c
@@ -89,6 +89,8 @@ remove_worktree(const char *worktree_path)
 		return 0;
 	if (!remove_meta_file(worktree_path, GOT_WORKTREE_PATH_PREFIX))
 		return 0;
+	if (!remove_meta_file(worktree_path, GOT_WORKTREE_BASE_COMMIT))
+		return 0;
 	if (!remove_meta_file(worktree_path, GOT_WORKTREE_LOCK))
 		return 0;
 	if (!remove_meta_file(worktree_path, GOT_WORKTREE_FORMAT))
@@ -172,6 +174,8 @@ worktree_init(const char *repo_path)
 		goto done;
 	if (!check_meta_file_exists(worktree_path, GOT_WORKTREE_LOCK))
 		goto done;
+	if (!check_meta_file_exists(worktree_path, GOT_WORKTREE_BASE_COMMIT))
+		goto done;
 	if (!check_meta_file_exists(worktree_path, GOT_WORKTREE_FILE_INDEX))
 		goto done;
 	if (!check_meta_file_exists(worktree_path, GOT_WORKTREE_REPOSITORY))
@@ -276,6 +280,9 @@ worktree_init_exists(const char *repo_path)
 	    GOT_WORKTREE_LOCK))
 		goto done;
 	if (!obstruct_meta_file_and_init(&ok, repo, worktree_path,
+	    GOT_WORKTREE_BASE_COMMIT))
+		goto done;
+	if (!obstruct_meta_file_and_init(&ok, repo, worktree_path,
 	    GOT_WORKTREE_FILE_INDEX))
 		goto done;
 	if (!obstruct_meta_file_and_init(&ok, repo, worktree_path,
@@ -292,9 +299,9 @@ done:
 	if (repo)
 		got_repo_close(repo);
 	free(gotpath);
-	if (ok == 6)
+	if (ok == 7)
 		remove_worktree(worktree_path);
-	return (ok == 6);
+	return (ok == 7);
 }
 
 #define RUN_TEST(expr, name) \