Esempio n. 1
0
        public virtual void CheckMergeConflictingNewTrees(MergeStrategy strategy)
        {
            Git git = Git.Wrap(db);

            WriteTrashFile("2", "orig");
            git.Add().AddFilepattern("2").Call();
            RevCommit first = git.Commit().SetMessage("added 2").Call();

            WriteTrashFile("d/1", "master");
            git.Add().AddFilepattern("d/1").Call();
            RevCommit masterCommit = git.Commit().SetAll(true).SetMessage("added d/1 on master"
                                                                          ).Call();

            git.Checkout().SetCreateBranch(true).SetStartPoint(first).SetName("side").Call();
            WriteTrashFile("d/1", "side");
            git.Add().AddFilepattern("d/1").Call();
            git.Commit().SetAll(true).SetMessage("added d/1 on side").Call();
            git.Rm().AddFilepattern("d/1").Call();
            git.Rm().AddFilepattern("d").Call();
            MergeCommandResult mergeRes = git.Merge().SetStrategy(strategy).Include(masterCommit
                                                                                    ).Call();

            NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, mergeRes.GetMergeStatus(
                                                ));
            NUnit.Framework.Assert.AreEqual("[2, mode:100644, content:orig][d/1, mode:100644, stage:2, content:side][d/1, mode:100644, stage:3, content:master]"
                                            , IndexState(CONTENT));
        }
Esempio n. 2
0
		public virtual void FailingPathsShouldNotResultInOKReturnValue(MergeStrategy strategy
			)
		{
			FilePath folder1 = new FilePath(db.WorkTree, "folder1");
			FileUtils.Mkdir(folder1);
			FilePath file = new FilePath(folder1, "file1.txt");
			Write(file, "folder1--file1.txt");
			file = new FilePath(folder1, "file2.txt");
			Write(file, "folder1--file2.txt");
			Git git = new Git(db);
			git.Add().AddFilepattern(folder1.GetName()).Call();
			RevCommit @base = git.Commit().SetMessage("adding folder").Call();
			RecursiveDelete(folder1);
			git.Rm().AddFilepattern("folder1/file1.txt").AddFilepattern("folder1/file2.txt").
				Call();
			RevCommit other = git.Commit().SetMessage("removing folders on 'other'").Call();
			git.Checkout().SetName(@base.Name).Call();
			file = new FilePath(db.WorkTree, "unrelated.txt");
			Write(file, "unrelated");
			git.Add().AddFilepattern("unrelated.txt").Call();
			RevCommit head = git.Commit().SetMessage("Adding another file").Call();
			// Untracked file to cause failing path for delete() of folder1
			file = new FilePath(folder1, "file3.txt");
			Write(file, "folder1--file3.txt");
			ResolveMerger merger = (ResolveMerger)strategy.NewMerger(db, false);
			merger.SetCommitNames(new string[] { "BASE", "HEAD", "other" });
			merger.SetWorkingTreeIterator(new FileTreeIterator(db));
			bool ok = merger.Merge(head.Id, other.Id);
			NUnit.Framework.Assert.IsFalse(merger.GetFailingPaths().IsEmpty());
			NUnit.Framework.Assert.IsFalse(ok);
		}
Esempio n. 3
0
        public virtual void CheckMergeMergeableFilesWithTreeInIndex(MergeStrategy strategy
                                                                    )
        {
            Git git = Git.Wrap(db);

            WriteTrashFile("0", "orig");
            WriteTrashFile("1", "1\n2\n3");
            git.Add().AddFilepattern("0").AddFilepattern("1").Call();
            RevCommit first = git.Commit().SetMessage("added 0, 1").Call();

            WriteTrashFile("1", "1master\n2\n3");
            RevCommit masterCommit = git.Commit().SetAll(true).SetMessage("modified 1 on master"
                                                                          ).Call();

            git.Checkout().SetCreateBranch(true).SetStartPoint(first).SetName("side").Call();
            WriteTrashFile("1", "1\n2\n3side");
            git.Commit().SetAll(true).SetMessage("modified 1 on side").Call();
            git.Rm().AddFilepattern("0").Call();
            WriteTrashFile("0/0", "modified");
            git.Add().AddFilepattern("0/0").Call();
            try
            {
                git.Merge().SetStrategy(strategy).Include(masterCommit).Call();
                NUnit.Framework.Assert.Fail("Didn't get the expected exception");
            }
            catch (NGit.Api.Errors.CheckoutConflictException e)
            {
                NUnit.Framework.Assert.AreEqual(1, e.GetConflictingPaths().Count);
                NUnit.Framework.Assert.AreEqual("0/0", e.GetConflictingPaths()[0]);
            }
        }
Esempio n. 4
0
 /// <summary>Get all registered strategies.</summary>
 /// <remarks>Get all registered strategies.</remarks>
 /// <returns>
 /// the registered strategy instances. No inherit order is returned;
 /// the caller may modify (and/or sort) the returned array if
 /// necessary to obtain a reasonable ordering.
 /// </returns>
 public static MergeStrategy[] Get()
 {
     lock (typeof(MergeStrategy))
     {
         MergeStrategy[] r = new MergeStrategy[STRATEGIES.Count];
         Sharpen.Collections.ToArray(STRATEGIES.Values, r);
         return(r);
     }
 }
Esempio n. 5
0
 /// <summary>Register a merge strategy so it can later be obtained by name.</summary>
 /// <remarks>Register a merge strategy so it can later be obtained by name.</remarks>
 /// <param name="name">name the strategy can be looked up under.</param>
 /// <param name="imp">the strategy to register.</param>
 /// <exception cref="System.ArgumentException">a strategy by the same name has already been registered.
 ///     </exception>
 public static void Register(string name, MergeStrategy imp)
 {
     lock (typeof(MergeStrategy))
     {
         if (STRATEGIES.ContainsKey(name))
         {
             throw new ArgumentException(MessageFormat.Format(JGitText.Get().mergeStrategyAlreadyExistsAsDefault
                                                              , name));
         }
         STRATEGIES.Put(name, imp);
     }
 }
Esempio n. 6
0
        public virtual void FailingPathsShouldNotResultInOKReturnValue(MergeStrategy strategy
                                                                       )
        {
            FilePath folder1 = new FilePath(db.WorkTree, "folder1");

            FileUtils.Mkdir(folder1);
            FilePath file = new FilePath(folder1, "file1.txt");

            Write(file, "folder1--file1.txt");
            file = new FilePath(folder1, "file2.txt");
            Write(file, "folder1--file2.txt");
            Git git = new Git(db);

            git.Add().AddFilepattern(folder1.GetName()).Call();
            RevCommit @base = git.Commit().SetMessage("adding folder").Call();

            RecursiveDelete(folder1);
            git.Rm().AddFilepattern("folder1/file1.txt").AddFilepattern("folder1/file2.txt").
            Call();
            RevCommit other = git.Commit().SetMessage("removing folders on 'other'").Call();

            git.Checkout().SetName(@base.Name).Call();
            file = new FilePath(db.WorkTree, "unrelated.txt");
            Write(file, "unrelated");
            git.Add().AddFilepattern("unrelated.txt").Call();
            RevCommit head = git.Commit().SetMessage("Adding another file").Call();

            // Untracked file to cause failing path for delete() of folder1
            file = new FilePath(folder1, "file3.txt");
            Write(file, "folder1--file3.txt");
            ResolveMerger merger = (ResolveMerger)strategy.NewMerger(db, false);

            merger.SetCommitNames(new string[] { "BASE", "HEAD", "other" });
            merger.SetWorkingTreeIterator(new FileTreeIterator(db));
            bool ok = merger.Merge(head.Id, other.Id);

            NUnit.Framework.Assert.IsFalse(merger.GetFailingPaths().IsEmpty());
            NUnit.Framework.Assert.IsFalse(ok);
        }
Esempio n. 7
0
        public virtual void CheckMergeConflictingFilesWithTreeInIndex(MergeStrategy strategy
                                                                      )
        {
            Git git = Git.Wrap(db);

            WriteTrashFile("0", "orig");
            git.Add().AddFilepattern("0").Call();
            RevCommit first = git.Commit().SetMessage("added 0").Call();

            WriteTrashFile("0", "master");
            RevCommit masterCommit = git.Commit().SetAll(true).SetMessage("modified 0 on master"
                                                                          ).Call();

            git.Checkout().SetCreateBranch(true).SetStartPoint(first).SetName("side").Call();
            WriteTrashFile("0", "side");
            git.Commit().SetAll(true).SetMessage("modified 0 on side").Call();
            git.Rm().AddFilepattern("0").Call();
            WriteTrashFile("0/0", "side");
            git.Add().AddFilepattern("0/0").Call();
            MergeCommandResult mergeRes = git.Merge().SetStrategy(strategy).Include(masterCommit
                                                                                    ).Call();

            NUnit.Framework.Assert.AreEqual(MergeStatus.FAILED, mergeRes.GetMergeStatus());
        }
Esempio n. 8
0
        public virtual void CheckMergeEqualTreesInCore(MergeStrategy strategy)
        {
            Git git = Git.Wrap(db);

            WriteTrashFile("d/1", "orig");
            git.Add().AddFilepattern("d/1").Call();
            RevCommit first = git.Commit().SetMessage("added d/1").Call();

            WriteTrashFile("d/1", "modified");
            RevCommit masterCommit = git.Commit().SetAll(true).SetMessage("modified d/1 on master"
                                                                          ).Call();

            git.Checkout().SetCreateBranch(true).SetStartPoint(first).SetName("side").Call();
            WriteTrashFile("d/1", "modified");
            RevCommit sideCommit = git.Commit().SetAll(true).SetMessage("modified d/1 on side"
                                                                        ).Call();

            git.Rm().AddFilepattern("d/1").Call();
            git.Rm().AddFilepattern("d").Call();
            ThreeWayMerger resolveMerger = (ThreeWayMerger)strategy.NewMerger(db, true);
            bool           noProblems    = resolveMerger.Merge(masterCommit, sideCommit);

            NUnit.Framework.Assert.IsTrue(noProblems);
        }
Esempio n. 9
0
        public virtual void CheckLockedFilesToBeDeleted(MergeStrategy strategy)
        {
            Git git = Git.Wrap(db);

            WriteTrashFile("a.txt", "orig");
            WriteTrashFile("b.txt", "orig");
            git.Add().AddFilepattern("a.txt").AddFilepattern("b.txt").Call();
            RevCommit first = git.Commit().SetMessage("added a.txt, b.txt").Call();

            // modify and delete files on the master branch
            WriteTrashFile("a.txt", "master");
            git.Rm().AddFilepattern("b.txt").Call();
            RevCommit masterCommit = git.Commit().SetMessage("modified a.txt, deleted b.txt")
                                     .SetAll(true).Call();

            // switch back to a side branch
            git.Checkout().SetCreateBranch(true).SetStartPoint(first).SetName("side").Call();
            WriteTrashFile("c.txt", "side");
            git.Add().AddFilepattern("c.txt").Call();
            git.Commit().SetMessage("added c.txt").Call();
            // Get a handle to the the file so on windows it can't be deleted.
            FileInputStream    fis      = new FileInputStream(new FilePath(db.WorkTree, "b.txt"));
            MergeCommandResult mergeRes = git.Merge().SetStrategy(strategy).Include(masterCommit
                                                                                    ).Call();

            if (mergeRes.GetMergeStatus().Equals(MergeStatus.FAILED))
            {
                // probably windows
                NUnit.Framework.Assert.AreEqual(1, mergeRes.GetFailingPaths().Count);
                NUnit.Framework.Assert.AreEqual(ResolveMerger.MergeFailureReason.COULD_NOT_DELETE
                                                , mergeRes.GetFailingPaths().Get("b.txt"));
            }
            NUnit.Framework.Assert.AreEqual("[a.txt, mode:100644, content:master]" + "[c.txt, mode:100644, content:side]"
                                            , IndexState(CONTENT));
            fis.Close();
        }
Esempio n. 10
0
        public virtual void CheckMergeEqualTreesWithoutIndex(MergeStrategy strategy)
        {
            Git git = Git.Wrap(db);

            WriteTrashFile("d/1", "orig");
            git.Add().AddFilepattern("d/1").Call();
            RevCommit first = git.Commit().SetMessage("added d/1").Call();

            WriteTrashFile("d/1", "modified");
            RevCommit masterCommit = git.Commit().SetAll(true).SetMessage("modified d/1 on master"
                                                                          ).Call();

            git.Checkout().SetCreateBranch(true).SetStartPoint(first).SetName("side").Call();
            WriteTrashFile("d/1", "modified");
            git.Commit().SetAll(true).SetMessage("modified d/1 on side").Call();
            git.Rm().AddFilepattern("d/1").Call();
            git.Rm().AddFilepattern("d").Call();
            MergeCommandResult mergeRes = git.Merge().SetStrategy(strategy).Include(masterCommit
                                                                                    ).Call();

            NUnit.Framework.Assert.AreEqual(MergeStatus.MERGED, mergeRes.GetMergeStatus());
            NUnit.Framework.Assert.AreEqual("[d/1, mode:100644, content:modified]", IndexState
                                                (CONTENT));
        }
Esempio n. 11
0
		/// <summary>Register a merge strategy so it can later be obtained by name.</summary>
		/// <remarks>Register a merge strategy so it can later be obtained by name.</remarks>
		/// <param name="name">name the strategy can be looked up under.</param>
		/// <param name="imp">the strategy to register.</param>
		/// <exception cref="System.ArgumentException">a strategy by the same name has already been registered.
		/// 	</exception>
		public static void Register(string name, MergeStrategy imp)
		{
			lock (typeof(MergeStrategy))
			{
				if (STRATEGIES.ContainsKey(name))
				{
					throw new ArgumentException(MessageFormat.Format(JGitText.Get().mergeStrategyAlreadyExistsAsDefault
						, name));
				}
				STRATEGIES.Put(name, imp);
			}
		}
Esempio n. 12
0
 // expected this exception
 /// <exception cref="System.Exception"></exception>
 //        [Theory]
 public virtual void TestMergeSuccessAllStrategies(MergeStrategy mergeStrategy)
 {
     Git git = new Git(db);
     RevCommit first = git.Commit().SetMessage("first").Call();
     CreateBranch(first, "refs/heads/side");
     WriteTrashFile("a", "a");
     git.Add().AddFilepattern("a").Call();
     git.Commit().SetMessage("second").Call();
     CheckoutBranch("refs/heads/side");
     WriteTrashFile("b", "b");
     git.Add().AddFilepattern("b").Call();
     git.Commit().SetMessage("third").Call();
     MergeCommandResult result = git.Merge().SetStrategy(mergeStrategy).Include(db.GetRef
         (Constants.MASTER)).Call();
     NUnit.Framework.Assert.AreEqual(MergeStatus.MERGED, result.GetMergeStatus());
     NUnit.Framework.Assert.AreEqual("merge refs/heads/master: Merge made by " + mergeStrategy
         .GetName() + ".", db.GetReflogReader(Constants.HEAD).GetLastEntry().GetComment()
         );
     NUnit.Framework.Assert.AreEqual("merge refs/heads/master: Merge made by " + mergeStrategy
         .GetName() + ".", db.GetReflogReader(db.GetBranch()).GetLastEntry().GetComment()
         );
 }
Esempio n. 13
0
 /// <summary>Register a merge strategy so it can later be obtained by name.</summary>
 /// <remarks>Register a merge strategy so it can later be obtained by name.</remarks>
 /// <param name="imp">the strategy to register.</param>
 /// <exception cref="System.ArgumentException">a strategy by the same name has already been registered.
 ///     </exception>
 public static void Register(MergeStrategy imp)
 {
     Register(imp.GetName(), imp);
 }
Esempio n. 14
0
		public virtual void CheckMergeConflictingNewTrees(MergeStrategy strategy)
		{
			Git git = Git.Wrap(db);
			WriteTrashFile("2", "orig");
			git.Add().AddFilepattern("2").Call();
			RevCommit first = git.Commit().SetMessage("added 2").Call();
			WriteTrashFile("d/1", "master");
			git.Add().AddFilepattern("d/1").Call();
			RevCommit masterCommit = git.Commit().SetAll(true).SetMessage("added d/1 on master"
				).Call();
			git.Checkout().SetCreateBranch(true).SetStartPoint(first).SetName("side").Call();
			WriteTrashFile("d/1", "side");
			git.Add().AddFilepattern("d/1").Call();
			git.Commit().SetAll(true).SetMessage("added d/1 on side").Call();
			git.Rm().AddFilepattern("d/1").Call();
			git.Rm().AddFilepattern("d").Call();
			MergeCommandResult mergeRes = git.Merge().SetStrategy(strategy).Include(masterCommit
				).Call();
			NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, mergeRes.GetMergeStatus(
				));
			NUnit.Framework.Assert.AreEqual("[2, mode:100644, content:orig][d/1, mode:100644, stage:2, content:side][d/1, mode:100644, stage:3, content:master]"
				, IndexState(CONTENT));
		}
Esempio n. 15
0
		public virtual void CheckMergeConflictingFilesWithTreeInIndex(MergeStrategy strategy
			)
		{
			Git git = Git.Wrap(db);
			WriteTrashFile("0", "orig");
			git.Add().AddFilepattern("0").Call();
			RevCommit first = git.Commit().SetMessage("added 0").Call();
			WriteTrashFile("0", "master");
			RevCommit masterCommit = git.Commit().SetAll(true).SetMessage("modified 0 on master"
				).Call();
			git.Checkout().SetCreateBranch(true).SetStartPoint(first).SetName("side").Call();
			WriteTrashFile("0", "side");
			git.Commit().SetAll(true).SetMessage("modified 0 on side").Call();
			git.Rm().AddFilepattern("0").Call();
			WriteTrashFile("0/0", "side");
			git.Add().AddFilepattern("0/0").Call();
			MergeCommandResult mergeRes = git.Merge().SetStrategy(strategy).Include(masterCommit
				).Call();
			NUnit.Framework.Assert.AreEqual(MergeStatus.FAILED, mergeRes.GetMergeStatus());
		}
Esempio n. 16
0
		/// <summary>
		/// Constructs a NoteMapMerger with custom
		/// <see cref="NoteMerger">NoteMerger</see>
		/// and custom
		/// <see cref="NGit.Merge.MergeStrategy">NGit.Merge.MergeStrategy</see>
		/// .
		/// </summary>
		/// <param name="db">Git repository</param>
		/// <param name="noteMerger">note merger for merging conflicting changes on a note</param>
		/// <param name="nonNotesMergeStrategy">merge strategy for merging non-note entries</param>
		public NoteMapMerger(Repository db, NoteMerger noteMerger, MergeStrategy nonNotesMergeStrategy
			)
		{
			this.db = db;
			this.reader = db.NewObjectReader();
			this.inserter = db.NewObjectInserter();
			this.noteMerger = noteMerger;
			this.nonNotesMergeStrategy = nonNotesMergeStrategy;
			this.objectIdPrefix = new MutableObjectId();
		}
Esempio n. 17
0
		public virtual void CheckMergeMergeableFilesWithTreeInIndex(MergeStrategy strategy
			)
		{
			Git git = Git.Wrap(db);
			WriteTrashFile("0", "orig");
			WriteTrashFile("1", "1\n2\n3");
			git.Add().AddFilepattern("0").AddFilepattern("1").Call();
			RevCommit first = git.Commit().SetMessage("added 0, 1").Call();
			WriteTrashFile("1", "1master\n2\n3");
			RevCommit masterCommit = git.Commit().SetAll(true).SetMessage("modified 1 on master"
				).Call();
			git.Checkout().SetCreateBranch(true).SetStartPoint(first).SetName("side").Call();
			WriteTrashFile("1", "1\n2\n3side");
			git.Commit().SetAll(true).SetMessage("modified 1 on side").Call();
			git.Rm().AddFilepattern("0").Call();
			WriteTrashFile("0/0", "modified");
			git.Add().AddFilepattern("0/0").Call();
			try
			{
				git.Merge().SetStrategy(strategy).Include(masterCommit).Call();
				NUnit.Framework.Assert.Fail("Didn't get the expected exception");
			}
			catch (NGit.Api.Errors.CheckoutConflictException e)
			{
				NUnit.Framework.Assert.AreEqual(1, e.GetConflictingPaths().Count);
				NUnit.Framework.Assert.AreEqual("0/0", e.GetConflictingPaths()[0]);
			}
		}
Esempio n. 18
0
        public virtual void CheckForCorrectIndex(MergeStrategy strategy)
        {
            FilePath f;
            long     lastTs4;
            long     lastTsIndex;
            Git      git       = Git.Wrap(db);
            FilePath indexFile = db.GetIndexFile();

            // Create initial content and remember when the last file was written.
            f       = WriteTrashFiles(false, "orig", "orig", "1\n2\n3", "orig", "orig");
            lastTs4 = f.LastModified();
            // add all files, commit and check this doesn't update any working tree
            // files and that the index is in a new file system timer tick. Make
            // sure to wait long enough before adding so the index doesn't contain
            // racily clean entries
            FsTick(f);
            git.Add().AddFilepattern(".").Call();
            RevCommit firstCommit = git.Commit().SetMessage("initial commit").Call();

            CheckConsistentLastModified("0", "1", "2", "3", "4");
            CheckModificationTimeStampOrder("1", "2", "3", "4", "<.git/index");
            NUnit.Framework.Assert.AreEqual(lastTs4, new FilePath(db.WorkTree, "4").LastModified
                                                (), "Commit should not touch working tree file 4");
            lastTsIndex = indexFile.LastModified();
            // Do modifications on the master branch. Then add and commit. This
            // should touch only "0", "2 and "3"
            FsTick(indexFile);
            f = WriteTrashFiles(false, "master", null, "1master\n2\n3", "master", null);
            FsTick(f);
            git.Add().AddFilepattern(".").Call();
            RevCommit masterCommit = git.Commit().SetMessage("master commit").Call();

            CheckConsistentLastModified("0", "1", "2", "3", "4");
            CheckModificationTimeStampOrder("1", "4", "*" + lastTs4, "<*" + lastTsIndex, "<0"
                                            , "2", "3", "<.git/index");
            lastTsIndex = indexFile.LastModified();
            // Checkout a side branch. This should touch only "0", "2 and "3"
            FsTick(indexFile);
            git.Checkout().SetCreateBranch(true).SetStartPoint(firstCommit).SetName("side").Call
                ();
            CheckConsistentLastModified("0", "1", "2", "3", "4");
            CheckModificationTimeStampOrder("1", "4", "*" + lastTs4, "<*" + lastTsIndex, "<0"
                                            , "2", "3", ".git/index");
            lastTsIndex = indexFile.LastModified();
            // This checkout may have populated worktree and index so fast that we
            // may have smudged entries now. Check that we have the right content
            // and then rewrite the index to get rid of smudged state
            NUnit.Framework.Assert.AreEqual("[0, mode:100644, content:orig]" + "[1, mode:100644, content:orig]"
                                            + "[2, mode:100644, content:1\n2\n3]" + "[3, mode:100644, content:orig]" + "[4, mode:100644, content:orig]"
                                            , IndexState(CONTENT));
            //
            //
            //
            //
            //
            FsTick(indexFile);
            f       = WriteTrashFiles(false, "orig", "orig", "1\n2\n3", "orig", "orig");
            lastTs4 = f.LastModified();
            FsTick(f);
            git.Add().AddFilepattern(".").Call();
            CheckConsistentLastModified("0", "1", "2", "3", "4");
            CheckModificationTimeStampOrder("*" + lastTsIndex, "<0", "1", "2", "3", "4", "<.git/index"
                                            );
            lastTsIndex = indexFile.LastModified();
            // Do modifications on the side branch. Touch only "1", "2 and "3"
            FsTick(indexFile);
            f = WriteTrashFiles(false, null, "side", "1\n2\n3side", "side", null);
            FsTick(f);
            git.Add().AddFilepattern(".").Call();
            git.Commit().SetMessage("side commit").Call();
            CheckConsistentLastModified("0", "1", "2", "3", "4");
            CheckModificationTimeStampOrder("0", "4", "*" + lastTs4, "<*" + lastTsIndex, "<1"
                                            , "2", "3", "<.git/index");
            lastTsIndex = indexFile.LastModified();
            // merge master and side. Should only touch "0," "2" and "3"
            FsTick(indexFile);
            git.Merge().SetStrategy(strategy).Include(masterCommit).Call();
            CheckConsistentLastModified("0", "1", "2", "4");
            CheckModificationTimeStampOrder("4", "*" + lastTs4, "<1", "<*" + lastTsIndex, "<0"
                                            , "2", "3", ".git/index");
            NUnit.Framework.Assert.AreEqual("[0, mode:100644, content:master]" + "[1, mode:100644, content:side]"
                                            + "[2, mode:100644, content:1master\n2\n3side\n]" + "[3, mode:100644, stage:1, content:orig][3, mode:100644, stage:2, content:side][3, mode:100644, stage:3, content:master]"
                                            + "[4, mode:100644, content:orig]", IndexState(CONTENT));
        }
Esempio n. 19
0
		public virtual void CheckMergeEqualTreesInCore(MergeStrategy strategy)
		{
			Git git = Git.Wrap(db);
			WriteTrashFile("d/1", "orig");
			git.Add().AddFilepattern("d/1").Call();
			RevCommit first = git.Commit().SetMessage("added d/1").Call();
			WriteTrashFile("d/1", "modified");
			RevCommit masterCommit = git.Commit().SetAll(true).SetMessage("modified d/1 on master"
				).Call();
			git.Checkout().SetCreateBranch(true).SetStartPoint(first).SetName("side").Call();
			WriteTrashFile("d/1", "modified");
			RevCommit sideCommit = git.Commit().SetAll(true).SetMessage("modified d/1 on side"
				).Call();
			git.Rm().AddFilepattern("d/1").Call();
			git.Rm().AddFilepattern("d").Call();
			ThreeWayMerger resolveMerger = (ThreeWayMerger)strategy.NewMerger(db, true);
			bool noProblems = resolveMerger.Merge(masterCommit, sideCommit);
			NUnit.Framework.Assert.IsTrue(noProblems);
		}
Esempio n. 20
0
		/// <summary>Get all registered strategies.</summary>
		/// <remarks>Get all registered strategies.</remarks>
		/// <returns>
		/// the registered strategy instances. No inherit order is returned;
		/// the caller may modify (and/or sort) the returned array if
		/// necessary to obtain a reasonable ordering.
		/// </returns>
		public static MergeStrategy[] Get()
		{
			lock (typeof(MergeStrategy))
			{
				MergeStrategy[] r = new MergeStrategy[STRATEGIES.Count];
				Sharpen.Collections.ToArray(STRATEGIES.Values, r);
				return r;
			}
		}
Esempio n. 21
0
		public virtual void CheckLockedFilesToBeDeleted(MergeStrategy strategy)
		{
			Git git = Git.Wrap(db);
			WriteTrashFile("a.txt", "orig");
			WriteTrashFile("b.txt", "orig");
			git.Add().AddFilepattern("a.txt").AddFilepattern("b.txt").Call();
			RevCommit first = git.Commit().SetMessage("added a.txt, b.txt").Call();
			// modify and delete files on the master branch
			WriteTrashFile("a.txt", "master");
			git.Rm().AddFilepattern("b.txt").Call();
			RevCommit masterCommit = git.Commit().SetMessage("modified a.txt, deleted b.txt")
				.SetAll(true).Call();
			// switch back to a side branch
			git.Checkout().SetCreateBranch(true).SetStartPoint(first).SetName("side").Call();
			WriteTrashFile("c.txt", "side");
			git.Add().AddFilepattern("c.txt").Call();
			git.Commit().SetMessage("added c.txt").Call();
			// Get a handle to the the file so on windows it can't be deleted.
			FileInputStream fis = new FileInputStream(new FilePath(db.WorkTree, "b.txt"));
			MergeCommandResult mergeRes = git.Merge().SetStrategy(strategy).Include(masterCommit
				).Call();
			if (mergeRes.GetMergeStatus().Equals(MergeStatus.FAILED))
			{
				// probably windows
				NUnit.Framework.Assert.AreEqual(1, mergeRes.GetFailingPaths().Count);
				NUnit.Framework.Assert.AreEqual(ResolveMerger.MergeFailureReason.COULD_NOT_DELETE
					, mergeRes.GetFailingPaths().Get("b.txt"));
			}
			NUnit.Framework.Assert.AreEqual("[a.txt, mode:100644, content:master]" + "[c.txt, mode:100644, content:side]"
				, IndexState(CONTENT));
			fis.Close();
		}
Esempio n. 22
0
		public virtual void CheckForCorrectIndex(MergeStrategy strategy)
		{
			FilePath f;
			long lastTs4;
			long lastTsIndex;
			Git git = Git.Wrap(db);
			FilePath indexFile = db.GetIndexFile();
			// Create initial content and remember when the last file was written.
			f = WriteTrashFiles(false, "orig", "orig", "1\n2\n3", "orig", "orig");
			lastTs4 = f.LastModified();
			// add all files, commit and check this doesn't update any working tree
			// files and that the index is in a new file system timer tick. Make
			// sure to wait long enough before adding so the index doesn't contain
			// racily clean entries
			FsTick(f);
			git.Add().AddFilepattern(".").Call();
			RevCommit firstCommit = git.Commit().SetMessage("initial commit").Call();
			CheckConsistentLastModified("0", "1", "2", "3", "4");
			CheckModificationTimeStampOrder("1", "2", "3", "4", "<.git/index");
			NUnit.Framework.Assert.AreEqual(lastTs4, new FilePath(db.WorkTree, "4").LastModified
				(), "Commit should not touch working tree file 4");
			lastTsIndex = indexFile.LastModified();
			// Do modifications on the master branch. Then add and commit. This
			// should touch only "0", "2 and "3"
			FsTick(indexFile);
			f = WriteTrashFiles(false, "master", null, "1master\n2\n3", "master", null);
			FsTick(f);
			git.Add().AddFilepattern(".").Call();
			RevCommit masterCommit = git.Commit().SetMessage("master commit").Call();
			CheckConsistentLastModified("0", "1", "2", "3", "4");
			CheckModificationTimeStampOrder("1", "4", "*" + lastTs4, "<*" + lastTsIndex, "<0"
				, "2", "3", "<.git/index");
			lastTsIndex = indexFile.LastModified();
			// Checkout a side branch. This should touch only "0", "2 and "3"
			FsTick(indexFile);
			git.Checkout().SetCreateBranch(true).SetStartPoint(firstCommit).SetName("side").Call
				();
			CheckConsistentLastModified("0", "1", "2", "3", "4");
			CheckModificationTimeStampOrder("1", "4", "*" + lastTs4, "<*" + lastTsIndex, "<0"
				, "2", "3", ".git/index");
			lastTsIndex = indexFile.LastModified();
			// This checkout may have populated worktree and index so fast that we
			// may have smudged entries now. Check that we have the right content
			// and then rewrite the index to get rid of smudged state
			NUnit.Framework.Assert.AreEqual("[0, mode:100644, content:orig]" + "[1, mode:100644, content:orig]"
				 + "[2, mode:100644, content:1\n2\n3]" + "[3, mode:100644, content:orig]" + "[4, mode:100644, content:orig]"
				, IndexState(CONTENT));
			//
			//
			//
			//
			//
			FsTick(indexFile);
			f = WriteTrashFiles(false, "orig", "orig", "1\n2\n3", "orig", "orig");
			lastTs4 = f.LastModified();
			FsTick(f);
			git.Add().AddFilepattern(".").Call();
			CheckConsistentLastModified("0", "1", "2", "3", "4");
			CheckModificationTimeStampOrder("*" + lastTsIndex, "<0", "1", "2", "3", "4", "<.git/index"
				);
			lastTsIndex = indexFile.LastModified();
			// Do modifications on the side branch. Touch only "1", "2 and "3"
			FsTick(indexFile);
			f = WriteTrashFiles(false, null, "side", "1\n2\n3side", "side", null);
			FsTick(f);
			git.Add().AddFilepattern(".").Call();
			git.Commit().SetMessage("side commit").Call();
			CheckConsistentLastModified("0", "1", "2", "3", "4");
			CheckModificationTimeStampOrder("0", "4", "*" + lastTs4, "<*" + lastTsIndex, "<1"
				, "2", "3", "<.git/index");
			lastTsIndex = indexFile.LastModified();
			// merge master and side. Should only touch "0," "2" and "3"
			FsTick(indexFile);
			git.Merge().SetStrategy(strategy).Include(masterCommit).Call();
			CheckConsistentLastModified("0", "1", "2", "4");
			CheckModificationTimeStampOrder("4", "*" + lastTs4, "<1", "<*" + lastTsIndex, "<0"
				, "2", "3", ".git/index");
			NUnit.Framework.Assert.AreEqual("[0, mode:100644, content:master]" + "[1, mode:100644, content:side]"
				 + "[2, mode:100644, content:1master\n2\n3side\n]" + "[3, mode:100644, stage:1, content:orig][3, mode:100644, stage:2, content:side][3, mode:100644, stage:3, content:master]"
				 + "[4, mode:100644, content:orig]", IndexState(CONTENT));
		}
Esempio n. 23
0
		/// <summary>Register a merge strategy so it can later be obtained by name.</summary>
		/// <remarks>Register a merge strategy so it can later be obtained by name.</remarks>
		/// <param name="imp">the strategy to register.</param>
		/// <exception cref="System.ArgumentException">a strategy by the same name has already been registered.
		/// 	</exception>
		public static void Register(MergeStrategy imp)
		{
			Register(imp.GetName(), imp);
		}
Esempio n. 24
0
		public virtual void CheckMergeEqualTreesWithoutIndex(MergeStrategy strategy)
		{
			Git git = Git.Wrap(db);
			WriteTrashFile("d/1", "orig");
			git.Add().AddFilepattern("d/1").Call();
			RevCommit first = git.Commit().SetMessage("added d/1").Call();
			WriteTrashFile("d/1", "modified");
			RevCommit masterCommit = git.Commit().SetAll(true).SetMessage("modified d/1 on master"
				).Call();
			git.Checkout().SetCreateBranch(true).SetStartPoint(first).SetName("side").Call();
			WriteTrashFile("d/1", "modified");
			git.Commit().SetAll(true).SetMessage("modified d/1 on side").Call();
			git.Rm().AddFilepattern("d/1").Call();
			git.Rm().AddFilepattern("d").Call();
			MergeCommandResult mergeRes = git.Merge().SetStrategy(strategy).Include(masterCommit
				).Call();
			NUnit.Framework.Assert.AreEqual(MergeStatus.MERGED, mergeRes.GetMergeStatus());
			NUnit.Framework.Assert.AreEqual("[d/1, mode:100644, content:modified]", IndexState
				(CONTENT));
		}