Reputation: 1588
I've checked the source code but couldn't find a method to retrieve SHA1 of a file from the ObjectDatabase by its path.
It's easy to calculate SHA1 manually but it requires reading a file which might cause performance issues.
Upvotes: 1
Views: 210
Reputation: 67609
If your file has been previously committed:
Commit commit = repo.Lookup<Commit>(commitSha);
// Or if it's just been committed
// Commit commit = repo.head.Tip;
string shaFromKnownCommit = commit["path/to/file.txt"].Target.Id.Sha;
If your file has only been staged (promoted to the staging area):
string shaFromStagedFile = repo.Index["path/to/file.txt"].Id.Sha;
Upvotes: 2