read / free the head ref when work tree is opened / closed
diff --git a/lib/got_worktree_priv.h b/lib/got_worktree_priv.h
index cef7d3d..f691b7a 100644
--- a/lib/got_worktree_priv.h
+++ b/lib/got_worktree_priv.h
@@ -19,6 +19,7 @@ struct got_worktree {
char *path_repo;
char *path_prefix;
char *base_commit;
+ char *head_ref;
/*
* File descriptor for the lock file, open while a work tree is open.
diff --git a/lib/worktree.c b/lib/worktree.c
index 4355b63..1293900 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -296,6 +296,11 @@ got_worktree_open(struct got_worktree **worktree, const char *path)
if (err)
goto done;
+ err = read_meta_file(&(*worktree)->head_ref, path_got,
+ GOT_WORKTREE_HEAD);
+ if (err)
+ goto done;
+
done:
free(path_got);
free(path_lock);
@@ -318,6 +323,7 @@ got_worktree_close(struct got_worktree *worktree)
free(worktree->path_repo);
free(worktree->path_prefix);
free(worktree->base_commit);
+ free(worktree->head_ref);
if (worktree->lockfd != -1)
close(worktree->lockfd);
free(worktree);