示例#1
0
		/// <param name="diff"></param>
		public Status(IndexDiff diff) : base()
		{
			this.diff = diff;
			clean = diff.GetAdded().IsEmpty() && diff.GetChanged().IsEmpty() && diff.GetRemoved
				().IsEmpty() && diff.GetMissing().IsEmpty() && diff.GetModified().IsEmpty() && diff
				.GetUntracked().IsEmpty() && diff.GetConflicting().IsEmpty();
		}
示例#2
0
        public virtual void TestConflictingFromMultipleCreations()
        {
            Git git = new Git(db);

            WriteTrashFile("a", "1\na\n3\n");
            git.Add().AddFilepattern("a").Call();
            RevCommit initialCommit = git.Commit().SetMessage("initial").Call();

            CreateBranch(initialCommit, "refs/heads/side");
            CheckoutBranch("refs/heads/side");
            WriteTrashFile("b", "1\nb(side)\n3\n");
            git.Add().AddFilepattern("b").Call();
            RevCommit secondCommit = git.Commit().SetMessage("side").Call();

            CheckoutBranch("refs/heads/master");
            WriteTrashFile("b", "1\nb(main)\n3\n");
            git.Add().AddFilepattern("b").Call();
            git.Commit().SetMessage("main").Call();
            MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy
                                                                                         .RESOLVE).Call();

            NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus());
            FileTreeIterator iterator = new FileTreeIterator(db);
            IndexDiff        diff     = new IndexDiff(db, Constants.HEAD, iterator);

            diff.Diff();
            NUnit.Framework.Assert.AreEqual("[]", new TreeSet <string>(diff.GetChanged()).ToString
                                                ());
            NUnit.Framework.Assert.AreEqual("[]", diff.GetAdded().ToString());
            NUnit.Framework.Assert.AreEqual("[]", diff.GetRemoved().ToString());
            NUnit.Framework.Assert.AreEqual("[]", diff.GetMissing().ToString());
            NUnit.Framework.Assert.AreEqual("[]", diff.GetModified().ToString());
            NUnit.Framework.Assert.AreEqual("[b]", diff.GetConflicting().ToString());
        }
        public virtual void TestConflicting()
        {
            Git git = new Git(db);

            WriteTrashFile("a", "1\na\n3\n");
            WriteTrashFile("b", "1\nb\n3\n");
            git.Add().AddFilepattern("a").AddFilepattern("b").Call();
            RevCommit initialCommit = git.Commit().SetMessage("initial").Call();

            // create side branch with two modifications
            CreateBranch(initialCommit, "refs/heads/side");
            CheckoutBranch("refs/heads/side");
            WriteTrashFile("a", "1\na(side)\n3\n");
            WriteTrashFile("b", "1\nb\n3\n(side)");
            git.Add().AddFilepattern("a").AddFilepattern("b").Call();
            RevCommit secondCommit = git.Commit().SetMessage("side").Call();

            // update a on master to generate conflict
            CheckoutBranch("refs/heads/master");
            WriteTrashFile("a", "1\na(main)\n3\n");
            git.Add().AddFilepattern("a").Call();
            git.Commit().SetMessage("main").Call();
            // merge side with master
            MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy
                                                                                         .RESOLVE).Call();

            NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus());
            FileTreeIterator iterator = new FileTreeIterator(db);
            IndexDiff        diff     = new IndexDiff(db, Constants.HEAD, iterator);

            diff.Diff();
            NUnit.Framework.CollectionAssert.AreEqual("[b]", new TreeSet <string>(diff.GetChanged()).ToString
                                                          ());
            NUnit.Framework.CollectionAssert.IsEmpty(diff.GetAdded());
            NUnit.Framework.CollectionAssert.IsEmpty(diff.GetRemoved());
            NUnit.Framework.CollectionAssert.IsEmpty(diff.GetMissing());
            NUnit.Framework.CollectionAssert.IsEmpty(diff.GetModified());
            NUnit.Framework.Assert.AreEqual("a", diff.GetConflicting().First());
            NUnit.Framework.Assert.AreEqual(1, diff.GetConflicting().Count());
            NUnit.Framework.CollectionAssert.IsEmpty(diff.GetUntrackedFolders());
        }
        public GitFileStatus GetFileStatusNoCache(string fileName)
        {
            //Debug.WriteLine(string.Format("===+ GetFileStatusNoCache {0}", fileName));

            var fileNameRel = GetRelativeFileNameForGit(fileName);

            IndexDiff indexDiff = new IndexDiff(repository, Constants.HEAD, new FileTreeIterator(repository));
            indexDiff.SetFilter(PathFilterGroup.CreateFromStrings(fileNameRel));
            indexDiff.Diff();

            if (indexDiff.GetModified().Count > 0)
                return GitFileStatus.Modified;

            if (indexDiff.GetConflicting().Count > 0)
                return GitFileStatus.Conflict;

            if (indexDiff.GetUntracked().Count > 0 || indexDiff.GetUntrackedFolders().Count > 0)
            {
                if (File.Exists(fileName))
                    return GitFileStatus.New;

                return GitFileStatus.NotControlled;
            }

            if (indexDiff.GetAdded().Count > 0)
                return GitFileStatus.Added;

            if (!File.Exists(fileName))
            {
                if (indexDiff.GetMissing().Count > 0)
                    return GitFileStatus.Removed;

                return GitFileStatus.Deleted;
            }

            if (indexDiff.GetChanged().Count > 0)
                return GitFileStatus.Staged;

            if (indexDiff.GetIgnoredNotInIndex().Count > 0)
                return GitFileStatus.Ignored;

            return GitFileStatus.Tracked;
        }
示例#5
0
 public virtual void TestConflictingFromMultipleCreations()
 {
     Git git = new Git(db);
     WriteTrashFile("a", "1\na\n3\n");
     git.Add().AddFilepattern("a").Call();
     RevCommit initialCommit = git.Commit().SetMessage("initial").Call();
     CreateBranch(initialCommit, "refs/heads/side");
     CheckoutBranch("refs/heads/side");
     WriteTrashFile("b", "1\nb(side)\n3\n");
     git.Add().AddFilepattern("b").Call();
     RevCommit secondCommit = git.Commit().SetMessage("side").Call();
     CheckoutBranch("refs/heads/master");
     WriteTrashFile("b", "1\nb(main)\n3\n");
     git.Add().AddFilepattern("b").Call();
     git.Commit().SetMessage("main").Call();
     MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy
         .RESOLVE).Call();
     NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus());
     FileTreeIterator iterator = new FileTreeIterator(db);
     IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
     diff.Diff();
     NUnit.Framework.Assert.AreEqual("[]", new TreeSet<string>(diff.GetChanged()).ToString
         ());
     NUnit.Framework.CollectionAssert.IsEmpty(diff.GetAdded());
     NUnit.Framework.CollectionAssert.IsEmpty(diff.GetRemoved());
     NUnit.Framework.CollectionAssert.IsEmpty(diff.GetMissing());
     NUnit.Framework.CollectionAssert.IsEmpty(diff.GetModified());
     NUnit.Framework.Assert.AreEqual(1, diff.GetConflicting().Count());
     NUnit.Framework.Assert.AreEqual("b", diff.GetConflicting().First());
     NUnit.Framework.CollectionAssert.IsEmpty(diff.GetUntrackedFolders()
         );
 }
示例#6
0
        protected void RaiseNotifyFromDiff(Repository repository)
        {
            if (repository == null)
                throw new ArgumentNullException("repository");
            var workingTreeIt = new FileTreeIterator(repository);
            var diff = new IndexDiff(repository, Constants.HEAD, workingTreeIt);

            diff.Diff();

            RaiseNotifyFromDiff(repository, diff.GetAdded(), GitNotifyAction.UpdateAdd);
            RaiseNotifyFromDiff(repository, diff.GetAssumeUnchanged(), GitNotifyAction.UpdateUpdate);
            RaiseNotifyFromDiff(repository, diff.GetChanged(), GitNotifyAction.UpdateUpdate);
            RaiseNotifyFromDiff(repository, diff.GetConflicting(), GitNotifyAction.UpdateUpdate);
            RaiseNotifyFromDiff(repository, diff.GetMissing(), GitNotifyAction.UpdateDeleted);
            RaiseNotifyFromDiff(repository, diff.GetModified(), GitNotifyAction.UpdateUpdate);
            RaiseNotifyFromDiff(repository, diff.GetRemoved(), GitNotifyAction.UpdateDeleted);
            RaiseNotifyFromDiff(repository, diff.GetUntracked(), GitNotifyAction.UpdateUpdate);
        }
示例#7
0
		public virtual void TestConflictingDeletedAndModified()
		{
			Git git = new Git(db);
			WriteTrashFile("a", "1\na\n3\n");
			WriteTrashFile("b", "1\nb\n3\n");
			git.Add().AddFilepattern("a").AddFilepattern("b").Call();
			RevCommit initialCommit = git.Commit().SetMessage("initial").Call();
			// create side branch and delete "a"
			CreateBranch(initialCommit, "refs/heads/side");
			CheckoutBranch("refs/heads/side");
			git.Rm().AddFilepattern("a").Call();
			RevCommit secondCommit = git.Commit().SetMessage("side").Call();
			// update a on master to generate conflict
			CheckoutBranch("refs/heads/master");
			WriteTrashFile("a", "1\na(main)\n3\n");
			git.Add().AddFilepattern("a").Call();
			git.Commit().SetMessage("main").Call();
			// merge side with master
			MergeCommandResult result = git.Merge().Include(secondCommit.Id).SetStrategy(MergeStrategy
				.RESOLVE).Call();
			NUnit.Framework.Assert.AreEqual(MergeStatus.CONFLICTING, result.GetMergeStatus());
			FileTreeIterator iterator = new FileTreeIterator(db);
			IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
			diff.Diff();
			NUnit.Framework.Assert.AreEqual("[]", new TreeSet<string>(diff.GetChanged()).ToString
				());
			NUnit.Framework.Assert.AreEqual("[]", diff.GetAdded().ToString());
			NUnit.Framework.Assert.AreEqual("[]", diff.GetRemoved().ToString());
			NUnit.Framework.Assert.AreEqual("[]", diff.GetMissing().ToString());
			NUnit.Framework.Assert.AreEqual("[]", diff.GetModified().ToString());
			NUnit.Framework.Assert.AreEqual("[a]", diff.GetConflicting().ToString());
		}