~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ngit/NGit.Test/NGit.Api/RebaseCommandTest.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
*/
43
43
 
44
44
using System;
 
45
using System.Collections.Generic;
45
46
using System.Text;
46
47
using NGit;
47
48
using NGit.Api;
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());
270
272
                }
271
273
 
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"
371
373
                                );
372
374
                        NUnit.Framework.Assert.AreEqual(RepositoryState.REBASING_INTERACTIVE, db.GetRepositoryState
373
375
                                ());
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"
681
 
                                );
 
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());
683
685
                }
684
686
 
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
893
895
                                , "UTF-8"));
894
896
                        NUnit.Framework.Assert.AreEqual(ident.GetName(), parsedIdent.GetName());
1256
1258
                        NUnit.Framework.Assert.AreEqual(RepositoryState.SAFE, db.GetRepositoryState());
1257
1259
                }
1258
1260
 
 
1261
                /// <exception cref="System.Exception"></exception>
 
1262
                [NUnit.Framework.Test]
 
1263
                public virtual void TestRebaseWithUncommittedDelete()
 
1264
                {
 
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();
 
1279
                        // do not commit
 
1280
                        // rebase
 
1281
                        RebaseResult result = git.Rebase().SetUpstream("refs/heads/master").Call();
 
1282
                        NUnit.Framework.Assert.AreEqual(RebaseResult.Status.FAST_FORWARD, result.GetStatus
 
1283
                                ());
 
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
 
1287
                                (CONTENT));
 
1288
                        NUnit.Framework.Assert.AreEqual(RepositoryState.SAFE, db.GetRepositoryState());
 
1289
                }
 
1290
 
1259
1291
                /// <exception cref="System.IO.IOException"></exception>
1260
1292
                private int CountPicks()
1261
1293
                {
1262
1294
                        int count = 0;
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"));
1266
1298
                        try
1365
1397
                        NUnit.Framework.Assert.AreEqual(RepositoryState.SAFE, git.GetRepository().GetRepositoryState
1366
1398
                                ());
1367
1399
                }
 
1400
 
 
1401
                /// <exception cref="System.IO.IOException"></exception>
 
1402
                [NUnit.Framework.Test]
 
1403
                public virtual void TestRebaseShouldBeAbleToHandleEmptyLinesInRebaseTodoFile()
 
1404
                {
 
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);
 
1414
                }
 
1415
 
 
1416
                private FilePath GetTodoFile()
 
1417
                {
 
1418
                        FilePath todoFile = new FilePath(db.Directory, "rebase-merge/git-rebase-todo");
 
1419
                        return todoFile;
 
1420
                }
1368
1421
        }
1369
1422
}