Enhance RepositoryTestCase.commitFile() to work on empty repository
Change-Id: Ic64497f0eedf8996ba593ca52dc9a040732a5b24 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
parent
7904060a5a
commit
e649287502
|
@ -463,16 +463,25 @@ protected File writeTrashFiles(boolean ensureDistinctTimestamps,
|
|||
protected RevCommit commitFile(String filename, String contents, String branch) {
|
||||
try {
|
||||
Git git = new Git(db);
|
||||
String originalBranch = git.getRepository().getFullBranch();
|
||||
if (git.getRepository().getRef(branch) == null)
|
||||
git.branchCreate().setName(branch).call();
|
||||
git.checkout().setName(branch).call();
|
||||
Repository repo = git.getRepository();
|
||||
String originalBranch = repo.getFullBranch();
|
||||
boolean empty = repo.resolve(Constants.HEAD) == null;
|
||||
if (!empty) {
|
||||
if (repo.getRef(branch) == null)
|
||||
git.branchCreate().setName(branch).call();
|
||||
git.checkout().setName(branch).call();
|
||||
}
|
||||
|
||||
writeTrashFile(filename, contents);
|
||||
git.add().addFilepattern(filename).call();
|
||||
RevCommit commit = git.commit()
|
||||
.setMessage(branch + ": " + filename).call();
|
||||
|
||||
if (originalBranch != null)
|
||||
git.checkout().setName(originalBranch).call();
|
||||
else if (empty)
|
||||
git.branchCreate().setName(branch).setStartPoint(commit).call();
|
||||
|
||||
return commit;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
|
Loading…
Reference in New Issue