259
260
// change third line in topic branch
260
261
WriteTrashFile(FILE1, "1\n2\n3\ntopic\n");
261
262
git.Add().AddFilepattern(FILE1).Call();
262
git.Commit().SetMessage("change file1 in topic").Call();
263
RevCommit origHead = git.Commit().SetMessage("change file1 in topic").Call();
263
264
RebaseResult res = git.Rebase().SetUpstream("refs/heads/master").Call();
264
265
NUnit.Framework.Assert.AreEqual(RebaseResult.Status.OK, res.GetStatus());
265
266
CheckFile(theFile, "1master\n2\n3\ntopic\n");
267
268
NUnit.Framework.Assert.AreEqual("refs/heads/topic", db.GetFullBranch());
268
269
NUnit.Framework.Assert.AreEqual(lastMasterChange, new RevWalk(db).ParseCommit(db.
269
270
Resolve(Constants.HEAD)).GetParent(0));
271
NUnit.Framework.Assert.AreEqual(origHead, db.ReadOrigHead());
272
274
/// <exception cref="System.Exception"></exception>
367
369
RebaseResult res = git.Rebase().SetUpstream("refs/heads/master").Call();
368
370
NUnit.Framework.Assert.AreEqual(RebaseResult.Status.STOPPED, res.GetStatus());
369
371
NUnit.Framework.Assert.AreEqual(conflicting, res.GetCurrentCommit());
370
CheckFile(FILE1, "<<<<<<< OURS\n1master\n=======\n1topic\n>>>>>>> THEIRS\n2\n3\ntopic4"
372
CheckFile(FILE1, "<<<<<<< Upstream, based on master\n1master\n=======\n1topic", ">>>>>>> e0d1dea change file1 in topic\n2\n3\ntopic4"
372
374
NUnit.Framework.Assert.AreEqual(RepositoryState.REBASING_INTERACTIVE, db.GetRepositoryState
677
679
NUnit.Framework.Assert.AreEqual(RebaseResult.Status.STOPPED, res.GetStatus());
678
680
res = git.Rebase().SetOperation(RebaseCommand.Operation.SKIP).Call();
679
681
// TODO is this correct? It is what the command line returns
680
CheckFile(FILE1, "1master\n2\n<<<<<<< OURS\n3master\n=======\n3topic\n>>>>>>> THEIRS\n4\n5topic"
682
CheckFile(FILE1, "1master\n2\n<<<<<<< Upstream, based on master\n3master\n=======\n3topic"
683
, ">>>>>>> 5afc8df change file1 in topic again\n4\n5topic");
682
684
NUnit.Framework.Assert.AreEqual(RebaseResult.Status.STOPPED, res.GetStatus());
872
874
string[] lines = convertedAuthor.Split("\n");
873
875
NUnit.Framework.Assert.AreEqual("GIT_AUTHOR_NAME='Author name'", lines[0]);
874
876
NUnit.Framework.Assert.AreEqual("GIT_AUTHOR_EMAIL='a.mail@some.com'", lines[1]);
875
NUnit.Framework.Assert.AreEqual("GIT_AUTHOR_DATE='123456789 -0100'", lines[2]);
877
NUnit.Framework.Assert.AreEqual("GIT_AUTHOR_DATE='@123456789 -0100'", lines[2]);
876
878
PersonIdent parsedIdent = git.Rebase().ParseAuthor(Sharpen.Runtime.GetBytesForString
877
879
(convertedAuthor, "UTF-8"));
878
880
NUnit.Framework.Assert.AreEqual(ident.GetName(), parsedIdent.GetName());
888
890
lines = convertedAuthor.Split("\n");
889
891
NUnit.Framework.Assert.AreEqual("GIT_AUTHOR_NAME='Author name'", lines[0]);
890
892
NUnit.Framework.Assert.AreEqual("GIT_AUTHOR_EMAIL='a.mail@some.com'", lines[1]);
891
NUnit.Framework.Assert.AreEqual("GIT_AUTHOR_DATE='123456789 +0930'", lines[2]);
893
NUnit.Framework.Assert.AreEqual("GIT_AUTHOR_DATE='@123456789 +0930'", lines[2]);
892
894
parsedIdent = git.Rebase().ParseAuthor(Sharpen.Runtime.GetBytesForString(convertedAuthor
894
896
NUnit.Framework.Assert.AreEqual(ident.GetName(), parsedIdent.GetName());
1256
1258
NUnit.Framework.Assert.AreEqual(RepositoryState.SAFE, db.GetRepositoryState());
1261
/// <exception cref="System.Exception"></exception>
1262
[NUnit.Framework.Test]
1263
public virtual void TestRebaseWithUncommittedDelete()
1265
// create file0 + file1, add and commit
1266
FilePath file0 = WriteTrashFile("file0", "file0");
1267
WriteTrashFile(FILE1, "file1");
1268
git.Add().AddFilepattern("file0").AddFilepattern(FILE1).Call();
1269
RevCommit commit = git.Commit().SetMessage("commit1").Call();
1270
// create topic branch
1271
CreateBranch(commit, "refs/heads/topic");
1272
// still on master / modify file1, add and commit
1273
WriteTrashFile(FILE1, "modified file1");
1274
git.Add().AddFilepattern(FILE1).Call();
1275
git.Commit().SetMessage("commit2").Call();
1276
// checkout topic branch / delete file0 and add to index
1277
CheckoutBranch("refs/heads/topic");
1278
git.Rm().AddFilepattern("file0").Call();
1281
RebaseResult result = git.Rebase().SetUpstream("refs/heads/master").Call();
1282
NUnit.Framework.Assert.AreEqual(RebaseResult.Status.FAST_FORWARD, result.GetStatus
1284
NUnit.Framework.Assert.IsFalse(file0.Exists(), "File should still be deleted");
1285
// index should only have updated file1
1286
NUnit.Framework.Assert.AreEqual("[file1, mode:100644, content:modified file1]", IndexState
1288
NUnit.Framework.Assert.AreEqual(RepositoryState.SAFE, db.GetRepositoryState());
1259
1291
/// <exception cref="System.IO.IOException"></exception>
1260
1292
private int CountPicks()
1263
FilePath todoFile = new FilePath(db.Directory, "rebase-merge/git-rebase-todo");
1295
FilePath todoFile = GetTodoFile();
1264
1296
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(
1265
1297
todoFile), "UTF-8"));
1365
1397
NUnit.Framework.Assert.AreEqual(RepositoryState.SAFE, git.GetRepository().GetRepositoryState
1401
/// <exception cref="System.IO.IOException"></exception>
1402
[NUnit.Framework.Test]
1403
public virtual void TestRebaseShouldBeAbleToHandleEmptyLinesInRebaseTodoFile()
1405
string emptyLine = "\n";
1406
string todo = "pick 1111111 Commit 1\n" + emptyLine + "pick 2222222 Commit 2\n" +
1407
emptyLine + "# Comment line at end\n";
1408
Write(GetTodoFile(), todo);
1409
RebaseCommand rebaseCommand = git.Rebase();
1410
IList<RebaseCommand.Step> steps = rebaseCommand.LoadSteps();
1411
NUnit.Framework.Assert.AreEqual(2, steps.Count);
1412
NUnit.Framework.Assert.AreEqual("1111111", steps[0].commit.Name);
1413
NUnit.Framework.Assert.AreEqual("2222222", steps[1].commit.Name);
1416
private FilePath GetTodoFile()
1418
FilePath todoFile = new FilePath(db.Directory, "rebase-merge/git-rebase-todo");