268
287
NUnit.Framework.Assert.AreEqual(path, subDiff.GetNewPath());
269
288
NUnit.Framework.Assert.AreEqual(path, subDiff.GetOldPath());
291
/// <exception cref="System.Exception"></exception>
292
[NUnit.Framework.Test]
293
public virtual void CommitUpdatesSmudgedEntries()
295
Git git = new Git(db);
296
FilePath file1 = WriteTrashFile("file1.txt", "content1");
297
NUnit.Framework.Assert.IsTrue(file1.SetLastModified(file1.LastModified() - 5000));
298
FilePath file2 = WriteTrashFile("file2.txt", "content2");
299
NUnit.Framework.Assert.IsTrue(file2.SetLastModified(file2.LastModified() - 5000));
300
FilePath file3 = WriteTrashFile("file3.txt", "content3");
301
NUnit.Framework.Assert.IsTrue(file3.SetLastModified(file3.LastModified() - 5000));
302
NUnit.Framework.Assert.IsNotNull(git.Add().AddFilepattern("file1.txt").AddFilepattern
303
("file2.txt").AddFilepattern("file3.txt").Call());
304
RevCommit commit = git.Commit().SetMessage("add files").Call();
305
NUnit.Framework.Assert.IsNotNull(commit);
306
DirCache cache = DirCache.Read(db.GetIndexFile(), db.FileSystem);
307
int file1Size = cache.GetEntry("file1.txt").Length;
308
int file2Size = cache.GetEntry("file2.txt").Length;
309
int file3Size = cache.GetEntry("file3.txt").Length;
310
ObjectId file2Id = cache.GetEntry("file2.txt").GetObjectId();
311
ObjectId file3Id = cache.GetEntry("file3.txt").GetObjectId();
312
NUnit.Framework.Assert.IsTrue(file1Size > 0);
313
NUnit.Framework.Assert.IsTrue(file2Size > 0);
314
NUnit.Framework.Assert.IsTrue(file3Size > 0);
316
cache = DirCache.Lock(db.GetIndexFile(), db.FileSystem);
317
cache.GetEntry("file1.txt").SetLength(0);
318
cache.GetEntry("file2.txt").SetLength(0);
319
cache.GetEntry("file3.txt").SetLength(0);
321
NUnit.Framework.Assert.IsTrue(cache.Commit());
322
// Verify entries smudged
323
cache = DirCache.Read(db.GetIndexFile(), db.FileSystem);
324
NUnit.Framework.Assert.AreEqual(0, cache.GetEntry("file1.txt").Length);
325
NUnit.Framework.Assert.AreEqual(0, cache.GetEntry("file2.txt").Length);
326
NUnit.Framework.Assert.AreEqual(0, cache.GetEntry("file3.txt").Length);
327
long indexTime = db.GetIndexFile().LastModified();
328
db.GetIndexFile().SetLastModified(indexTime - 5000);
329
Write(file1, "content4");
330
NUnit.Framework.Assert.IsTrue(file1.SetLastModified(file1.LastModified() + 2500));
331
NUnit.Framework.Assert.IsNotNull(git.Commit().SetMessage("edit file").SetOnly("file1.txt"
333
cache = db.ReadDirCache();
334
NUnit.Framework.Assert.AreEqual(file1Size, cache.GetEntry("file1.txt").Length);
335
NUnit.Framework.Assert.AreEqual(file2Size, cache.GetEntry("file2.txt").Length);
336
NUnit.Framework.Assert.AreEqual(file3Size, cache.GetEntry("file3.txt").Length);
337
NUnit.Framework.Assert.AreEqual(file2Id, cache.GetEntry("file2.txt").GetObjectId(
339
NUnit.Framework.Assert.AreEqual(file3Id, cache.GetEntry("file3.txt").GetObjectId(
343
/// <exception cref="System.Exception"></exception>
344
[NUnit.Framework.Test]
345
public virtual void CommitIgnoresSmudgedEntryWithDifferentId()
347
Git git = new Git(db);
348
FilePath file1 = WriteTrashFile("file1.txt", "content1");
349
NUnit.Framework.Assert.IsTrue(file1.SetLastModified(file1.LastModified() - 5000));
350
FilePath file2 = WriteTrashFile("file2.txt", "content2");
351
NUnit.Framework.Assert.IsTrue(file2.SetLastModified(file2.LastModified() - 5000));
352
NUnit.Framework.Assert.IsNotNull(git.Add().AddFilepattern("file1.txt").AddFilepattern
353
("file2.txt").Call());
354
RevCommit commit = git.Commit().SetMessage("add files").Call();
355
NUnit.Framework.Assert.IsNotNull(commit);
356
DirCache cache = DirCache.Read(db.GetIndexFile(), db.FileSystem);
357
int file1Size = cache.GetEntry("file1.txt").Length;
358
int file2Size = cache.GetEntry("file2.txt").Length;
359
NUnit.Framework.Assert.IsTrue(file1Size > 0);
360
NUnit.Framework.Assert.IsTrue(file2Size > 0);
361
WriteTrashFile("file2.txt", "content3");
362
NUnit.Framework.Assert.IsNotNull(git.Add().AddFilepattern("file2.txt").Call());
363
WriteTrashFile("file2.txt", "content4");
365
cache = DirCache.Lock(db.GetIndexFile(), db.FileSystem);
366
cache.GetEntry("file1.txt").SetLength(0);
367
cache.GetEntry("file2.txt").SetLength(0);
369
NUnit.Framework.Assert.IsTrue(cache.Commit());
370
// Verify entries smudged
371
cache = db.ReadDirCache();
372
NUnit.Framework.Assert.AreEqual(0, cache.GetEntry("file1.txt").Length);
373
NUnit.Framework.Assert.AreEqual(0, cache.GetEntry("file2.txt").Length);
374
long indexTime = db.GetIndexFile().LastModified();
375
db.GetIndexFile().SetLastModified(indexTime - 5000);
376
Write(file1, "content5");
377
NUnit.Framework.Assert.IsTrue(file1.SetLastModified(file1.LastModified() + 1000));
378
NUnit.Framework.Assert.IsNotNull(git.Commit().SetMessage("edit file").SetOnly("file1.txt"
380
cache = db.ReadDirCache();
381
NUnit.Framework.Assert.AreEqual(file1Size, cache.GetEntry("file1.txt").Length);
382
NUnit.Framework.Assert.AreEqual(0, cache.GetEntry("file2.txt").Length);
385
/// <exception cref="System.Exception"></exception>
386
[NUnit.Framework.Test]
387
public virtual void CommitAfterSquashMerge()
389
Git git = new Git(db);
390
WriteTrashFile("file1", "file1");
391
git.Add().AddFilepattern("file1").Call();
392
RevCommit first = git.Commit().SetMessage("initial commit").Call();
393
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file1").Exists());
394
CreateBranch(first, "refs/heads/branch1");
395
CheckoutBranch("refs/heads/branch1");
396
WriteTrashFile("file2", "file2");
397
git.Add().AddFilepattern("file2").Call();
398
git.Commit().SetMessage("second commit").Call();
399
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file2").Exists());
400
CheckoutBranch("refs/heads/master");
401
MergeCommandResult result = git.Merge().Include(db.GetRef("branch1")).SetSquash(true
403
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file1").Exists());
404
NUnit.Framework.Assert.IsTrue(new FilePath(db.WorkTree, "file2").Exists());
405
NUnit.Framework.Assert.AreEqual(MergeStatus.FAST_FORWARD_SQUASHED, result.GetMergeStatus
407
// comment not set, should be inferred from SQUASH_MSG
408
RevCommit squashedCommit = git.Commit().Call();
409
NUnit.Framework.Assert.AreEqual(1, squashedCommit.ParentCount);
410
NUnit.Framework.Assert.IsNull(db.ReadSquashCommitMsg());
411
NUnit.Framework.Assert.AreEqual("commit: Squashed commit of the following:", db.GetReflogReader
412
(Constants.HEAD).GetLastEntry().GetComment());
413
NUnit.Framework.Assert.AreEqual("commit: Squashed commit of the following:", db.GetReflogReader
414
(db.GetBranch()).GetLastEntry().GetComment());
417
/// <exception cref="System.Exception"></exception>
418
public virtual void CommitAmendOnInitialShouldFail()
420
Git git = new Git(db);
421
git.Commit().SetAmend(true).SetMessage("initial commit").Call();
424
/// <exception cref="System.Exception"></exception>
425
[NUnit.Framework.Test]
426
public virtual void CommitAmendWithoutAuthorShouldSetOriginalAuthorAndAuthorTime(
429
Git git = new Git(db);
430
WriteTrashFile("file1", "file1");
431
git.Add().AddFilepattern("file1").Call();
432
string authorName = "First Author";
433
string authorEmail = "author@example.org";
434
DateTime authorDate = Sharpen.Extensions.CreateDate(1349621117000L);
435
PersonIdent firstAuthor = new PersonIdent(authorName, authorEmail, authorDate, Sharpen.Extensions.GetTimeZone
437
git.Commit().SetMessage("initial commit").SetAuthor(firstAuthor).Call();
438
RevCommit amended = git.Commit().SetAmend(true).SetMessage("amend commit").Call();
439
PersonIdent amendedAuthor = amended.GetAuthorIdent();
440
NUnit.Framework.Assert.AreEqual(authorName, amendedAuthor.GetName());
441
NUnit.Framework.Assert.AreEqual(authorEmail, amendedAuthor.GetEmailAddress());
442
NUnit.Framework.Assert.AreEqual(authorDate.GetTime(), amendedAuthor.GetWhen().GetTime
446
/// <exception cref="System.Exception"></exception>
447
[NUnit.Framework.Test]
448
public virtual void CommitAmendWithAuthorShouldUseIt()
450
Git git = new Git(db);
451
WriteTrashFile("file1", "file1");
452
git.Add().AddFilepattern("file1").Call();
453
git.Commit().SetMessage("initial commit").Call();
454
RevCommit amended = git.Commit().SetAmend(true).SetAuthor("New Author", "newauthor@example.org"
455
).SetMessage("amend commit").Call();
456
PersonIdent amendedAuthor = amended.GetAuthorIdent();
457
NUnit.Framework.Assert.AreEqual("New Author", amendedAuthor.GetName());
458
NUnit.Framework.Assert.AreEqual("newauthor@example.org", amendedAuthor.GetEmailAddress