summaryrefslogtreecommitdiff
path: root/src/repo.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2019-07-28 13:21:33 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2019-07-28 13:21:33 +0100
commit801b1a160558ed8b862e683c7aaf5092b0c1adb2 (patch)
treecdfd96d7f5164195e722f2c0d6df70c1613fa357 /src/repo.cpp
parentReplace hard-coded test values with properties (diff)
downloadnetfs-gitfs-801b1a160558ed8b862e683c7aaf5092b0c1adb2.tar.bz2
netfs-gitfs-801b1a160558ed8b862e683c7aaf5092b0c1adb2.tar.xz
netfs-gitfs-801b1a160558ed8b862e683c7aaf5092b0c1adb2.zip
Support working tree based on a commit, tag or branch
Diffstat (limited to 'src/repo.cpp')
-rw-r--r--src/repo.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/repo.cpp b/src/repo.cpp
index 4059897..0da7e4a 100644
--- a/src/repo.cpp
+++ b/src/repo.cpp
@@ -11,11 +11,23 @@ std::string operator/(const std::string & a, const std::string & b)
GitFS::Repo::Repo(const PropertyReader & properties) :
repo(Git::RepositoryOpenBare(properties("gitdir"))),
- commit(Git::CommitLookup(repo, Git::OidParse(properties("commit")))),
- tree(Git::TreeLookup(repo, *git_commit_tree_id(commit.get()))),
+ commitish(properties("commitish") / "master"),
gid(properties("gid") / "root"),
uid(properties("uid") / "root")
{
+ git_oid commitId;
+ if (commitish.length() == GIT_OID_HEXSZ) {
+ commitId = Git::OidParse(commitish);
+ }
+ else {
+ auto ref = Git::Commitish(repo, commitish);
+ isBranch = git_reference_is_branch(ref.get());
+ ref = Git::Resolve(ref);
+ commitId = *git_reference_target(ref.get());
+ }
+
+ commit = Git::CommitLookup(repo, commitId);
+ tree = Git::TreeLookup(repo, *git_commit_tree_id(commit.get()));
}
void