diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2013-10-21 01:22:08 +0200 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2013-10-31 08:28:46 -0400 |
commit | e649287502407e10c89de03e82cc0de855e01dcf (patch) | |
tree | e768ce0c14a4ea9b449a0786810537cd244ee445 /org.eclipse.jgit.junit | |
parent | 7904060a5a6a986550773ed59bfd7e02f88090b7 (diff) | |
download | jgit-e649287502407e10c89de03e82cc0de855e01dcf.tar.gz jgit-e649287502407e10c89de03e82cc0de855e01dcf.zip |
Enhance RepositoryTestCase.commitFile() to work on empty repository
Change-Id: Ic64497f0eedf8996ba593ca52dc9a040732a5b24
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.junit')
-rw-r--r-- | org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java index 7b12ce1b21..15334ee396 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java @@ -463,16 +463,25 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { 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); |