|
|
@ -463,16 +463,25 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { |
|
|
|
protected RevCommit commitFile(String filename, String contents, String branch) { |
|
|
|
protected RevCommit commitFile(String filename, String contents, String branch) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
Git git = new Git(db); |
|
|
|
Git git = new Git(db); |
|
|
|
String originalBranch = git.getRepository().getFullBranch(); |
|
|
|
Repository repo = git.getRepository(); |
|
|
|
if (git.getRepository().getRef(branch) == null) |
|
|
|
String originalBranch = repo.getFullBranch(); |
|
|
|
|
|
|
|
boolean empty = repo.resolve(Constants.HEAD) == null; |
|
|
|
|
|
|
|
if (!empty) { |
|
|
|
|
|
|
|
if (repo.getRef(branch) == null) |
|
|
|
git.branchCreate().setName(branch).call(); |
|
|
|
git.branchCreate().setName(branch).call(); |
|
|
|
git.checkout().setName(branch).call(); |
|
|
|
git.checkout().setName(branch).call(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
writeTrashFile(filename, contents); |
|
|
|
writeTrashFile(filename, contents); |
|
|
|
git.add().addFilepattern(filename).call(); |
|
|
|
git.add().addFilepattern(filename).call(); |
|
|
|
RevCommit commit = git.commit() |
|
|
|
RevCommit commit = git.commit() |
|
|
|
.setMessage(branch + ": " + filename).call(); |
|
|
|
.setMessage(branch + ": " + filename).call(); |
|
|
|
|
|
|
|
|
|
|
|
if (originalBranch != null) |
|
|
|
if (originalBranch != null) |
|
|
|
git.checkout().setName(originalBranch).call(); |
|
|
|
git.checkout().setName(originalBranch).call(); |
|
|
|
|
|
|
|
else if (empty) |
|
|
|
|
|
|
|
git.branchCreate().setName(branch).setStartPoint(commit).call(); |
|
|
|
|
|
|
|
|
|
|
|
return commit; |
|
|
|
return commit; |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
throw new RuntimeException(e); |
|
|
|