import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.lib.StoredConfig;
-import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
writeToFile(sourceFile, "Hello world");
// and commit it
source.add().addFilepattern("SomeFile.txt").call();
- RevCommit commit = source.commit().setMessage(
- "Initial commit for source").call();
-
- // point the master branch to the new commit
- RefUpdate upd = dbTarget.updateRef("refs/heads/master");
- upd.setNewObjectId(commit.getId());
- upd.update();
+ source.commit().setMessage("Initial commit for source").call();
// configure the target repo to connect to the source via "origin"
StoredConfig targetConfig = dbTarget.getConfig();
targetConfig.save();
targetFile = new File(dbTarget.getWorkTree(), "SomeFile.txt");
- writeToFile(targetFile, "Hello world");
// make sure we have the same content
target.pull().call();
+ assertFileContentsEqual(targetFile, "Hello world");
}
private void writeToFile(File actFile, String string) throws IOException {
writeTrashFile("foo", "foo");
go();
+ // test that we don't overwrite untracked files when there is a HEAD
+ recursiveDelete(new File(trash, "foo"));
+ setupCase(mk("other"), mkmap("other", "other", "foo", "foo"),
+ mk("other"));
+ writeTrashFile("foo", "bar");
+ try {
+ checkout();
+ fail("didn't get the expected exception");
+ } catch (CheckoutConflictException e) {
+ assertConflict("foo");
+ assertWorkDir(mkmap("foo", "bar", "other", "other"));
+ assertIndex(mk("other"));
+ }
+
+ // test that we don't overwrite untracked files when there is no HEAD
+ recursiveDelete(new File(trash, "other"));
+ recursiveDelete(new File(trash, "foo"));
+ setupCase(null, mk("foo"), null);
+ writeTrashFile("foo", "bar");
+ try {
+ checkout();
+ fail("didn't get the expected exception");
+ } catch (CheckoutConflictException e) {
+ assertConflict("foo");
+ assertWorkDir(mkmap("foo", "bar"));
+ assertIndex(mkmap());
+ }
+
// TODO: Why should we expect conflicts here?
// H and M are emtpy and according to rule #5 of
// the carry-over rules a dirty index is no reason
// assertConflict("foo");
recursiveDelete(new File(trash, "foo"));
+ recursiveDelete(new File(trash, "other"));
setupCase(null, mk("foo"), null);
writeTrashFile("foo/bar/baz", "");
writeTrashFile("foo/blahblah", "");
* @param m the tree to merge
* @param i the index
* @param f the working tree
+ * @throws IOException
*/
void processEntry(CanonicalTreeParser m, DirCacheBuildIterator i,
- WorkingTreeIterator f) {
+ WorkingTreeIterator f) throws IOException {
if (m != null) {
// There is an entry in the merge commit. Means: we want to update
// what's currently in the index and working-tree to that one
if (i == null) {
// The index entry is missing
- update(m.getEntryPathString(), m.getEntryObjectId(),
+ if (f != null && !FileMode.TREE.equals(f.getEntryFileMode())
+ && !f.isEntryIgnored()) {
+ // don't overwrite an untracked and not ignored file
+ conflicts.add(walk.getPathString());
+ } else
+ update(m.getEntryPathString(), m.getEntryObjectId(),
m.getEntryFileMode());
} else if (f == null || !m.idEqual(i)) {
// The working tree file is missing or the merge content differs
// conflicts set
remove(i.getEntryPathString());
conflicts.remove(i.getEntryPathString());
+ } else {
+ // We are about to remove an untracked file. Check that
+ // it is ignored - otherwise that's an conflict
+ if (!f.isEntryIgnored())
+ conflicts.add(walk.getPathString());
+ else
+ remove(f.getEntryPathString());
}
}
} else {
}
if (i == null) {
+ // make sure not to overwrite untracked files
+ if (f != null) {
+ // a dirty worktree: the index is empty but we have a
+ // workingtree-file
+ if (mId == null || !mId.equals(f.getEntryObjectId())) {
+ conflict(name, null, h, m);
+ return;
+ }
+ }
+
/**
* <pre>
* I (index) H M Result