Commit 5166488913ca69fd4d6c284f8bee054b6bf1d073

Stefan Sperling 2018-03-12T13:41:13

in got_worktree_checkout_files, init file index path before using

diff --git a/lib/worktree.c b/lib/worktree.c
index 5543614..78b75a9 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -576,11 +576,6 @@ got_worktree_checkout_files(struct got_worktree *worktree,
 		goto done;
 	}
 
-	err = got_opentemp_named(&new_fileindex_path, &findex, fileindex_path);
-	if (err)
-		goto done;
-
-
 	if (asprintf(&fileindex_path, "%s/%s/%s", worktree->root_path,
 	    GOT_WORKTREE_GOT_DIR, GOT_WORKTREE_FILE_INDEX) == -1) {
 		err = got_error(GOT_ERR_NO_MEM);
@@ -588,6 +583,10 @@ got_worktree_checkout_files(struct got_worktree *worktree,
 		goto done;
 	}
 
+	err = got_opentemp_named(&new_fileindex_path, &findex, fileindex_path);
+	if (err)
+		goto done;
+
 	err = got_ref_resolve(&commit_id, repo, head_ref);
 	if (err)
 		goto done;