When starting an anonymous transaction then transaction starts on the same commit

This commit is contained in:
Paul Campbell 2018-06-15 18:38:34 +01:00
parent 71bb51c729
commit 1a65fb9123
3 changed files with 14 additions and 2 deletions

View file

@ -229,6 +229,6 @@ class GitDBRepo {
} }
Ref createBranch(final Ref branchRef, final String name) throws IOException { Ref createBranch(final Ref branchRef, final String name) throws IOException {
return repository.getRefDatabase().newUpdate(name, false).getRef(); return writeHead(branchRef.getName(), branchRef.getObjectId());
} }
} }

View file

@ -79,6 +79,6 @@ class GitDBTransactionImpl implements GitDBTransaction {
@Override @Override
public String getCommitId() { public String getCommitId() {
return null; return branch.getCommitId();
} }
} }

View file

@ -353,6 +353,18 @@ class GitDBTest implements WithAssertions {
assertThat(gitDB.branch("master").map(GitDBBranch::getCommitId)).contains(commitId); assertThat(gitDB.branch("master").map(GitDBBranch::getCommitId)).contains(commitId);
} }
// When starting an anonymous transaction then transaction starts on the same commit
@Test
void startAnonymousTransaction_thenTransactionCommitMatchesOriginal() throws IOException {
//given
final GitDBBranch gitDBBranch = gitDBBranch();
final String commitId = gitDBBranch.getCommitId();
//when
final GitDBTransaction transaction = gitDBBranch.transaction();
//then
assertThat(transaction.getCommitId()).isEqualTo(commitId);
}
// Given a GitDbTransaction handle (i.e. a new branch) // Given a GitDbTransaction handle (i.e. a new branch)
// When putting a new key/value pair then the original GitDbBranch can't find it // When putting a new key/value pair then the original GitDbBranch can't find it
@Test @Test