Exemplo n.º 1
0
        public void TestIgnore1()
        {
            IgnoreRules rules = GetRules();

            Assert.AreEqual(true, rules.IgnoreDir("project/", "project/src/bin"));
            Assert.AreEqual(true, rules.IgnoreDir("project/", "project/src/bin/Project.dll"));
            Assert.AreEqual(true, rules.IgnoreDir("project/", "project/src/bin/Project.pdb"));
        }
Exemplo n.º 2
0
        public void TestIgnore()
        {
            IgnoreRules rules = GetRules();

            Assert.AreEqual(false, rules.IgnoreFile("project/", "project/Documentation/foo.html"));
            Assert.AreEqual(true, rules.IgnoreFile("project/", "project/Documentation/gitignore.html"));
            Assert.AreEqual(false, rules.IgnoreFile("project/", "project/src/Documentation/index.html"));
            Assert.AreEqual(true, rules.IgnoreFile("project/", "project/Documentation/index.html"));
            Assert.AreEqual(true, rules.IgnoreFile("project/", "project/gitignore.html"));

            Assert.AreEqual(true, rules.IgnoreFile("project/", "project/file.o"));
            Assert.AreEqual(true, rules.IgnoreFile("project/", "project/lib.a"));
            Assert.AreEqual(true, rules.IgnoreFile("project/", "project/src/internal.o"));

            Assert.AreEqual(false, rules.IgnoreFile("project/", "project/Program.cs"));
            Assert.AreEqual(false, rules.IgnoreFile("project/", "project/Program.suo"));

            Assert.AreEqual(false, rules.IgnoreFile("project/", "project/bin"));
            Assert.AreEqual(false, rules.IgnoreDir("project/", "project/bin"));
            Assert.AreEqual(false, rules.IgnoreFile("project/", "project/data/bin"));
        }
Exemplo n.º 3
0
        public override void Execute()
        {
            RepositoryStatus status = new RepositoryStatus(Repository);

            IgnoreRules rules;

            //Read ignore file list and remove from the untracked list
            try
            {
                rules = new IgnoreRules(Path.Combine(Repository.WorkingDirectory, ".gitignore"));
            }
            catch (FileNotFoundException)
            {
                //.gitignore file does not exist for a newly initialized repository.
                string[] lines = {};
                rules = new IgnoreRules(lines);
            }

            foreach (string hash in status.Untracked)
            {
                string path = Path.Combine(Repository.WorkingDirectory, hash);
                if (!rules.IgnoreFile(Repository.WorkingDirectory, path) && !rules.IgnoreDir(Repository.WorkingDirectory, path))
                {
                    results.UntrackedList.Add(hash);
                }
            }

            if (status.AnyDifferences || results.UntrackedList.Count > 0)
            {
                // Files use the following StatusTypes: removed, missing, added, and modified, modified w/staged, and merge conflict.
                // The following StatusStates are defined for each type:
                //              Modified -> Unstaged
                //         MergeConflict -> Unstaged
                //                 Added -> Staged
                //        ModifiedStaged -> Staged
                //               Removed -> Staged
                //               Missing -> Staged
                // The StatusState known as "Untracked" is determined by what is *not* defined in any state.
                // It is then intersected with the .gitignore list to determine what should be listed as untracked.

                HashSet<string> hset = new HashSet<string>(status.MergeConflict);
                foreach (string hash in hset)
                {
                    results.ModifiedList.Add(hash, StatusType.MergeConflict);
                    status.Staged.Remove(hash);
                    status.Modified.Remove(hash);
                }

                hset = new HashSet<string>(status.Missing);
                foreach (string hash in hset)
                    results.ModifiedList.Add(hash, StatusType.Missing);

                hset = new HashSet<string>(status.Modified);
                foreach (string hash in hset)
                    results.ModifiedList.Add(hash, StatusType.Modified);

                hset = new HashSet<string>(status.Staged);
                foreach (string hash in hset)
                    results.StagedList.Add(hash, StatusType.ModifiedStaged);

                hset = new HashSet<string>(status.Added);
                foreach (string hash in hset)
                    results.StagedList.Add(hash, StatusType.Added);

                hset = new HashSet<string>(status.Removed);
                foreach (string hash in hset)
                    results.StagedList.Add(hash, StatusType.Removed);

                results.UntrackedList.Sort();
                results.ModifiedList.OrderBy(v => v.Key);
                results.StagedList.OrderBy(v => v.Key);
            }

            IndexSize = Repository.Index.Size;
        }
Exemplo n.º 4
0
        public override void Execute()
        {
            RepositoryStatus status = new RepositoryStatus(Repository);
            IgnoreRules rules;

            //Read ignore file list and remove from the untracked list
            try
            {
                rules = new IgnoreRules(Path.Combine(Repository.WorkingDirectory, ".gitignore"));
            }
            catch (FileNotFoundException)
            {
                //.gitignore file does not exist for a newly initialized repository.
                string[] lines = {};
                rules = new IgnoreRules(lines);
            }

            foreach (string hash in status.Untracked)
            {
                string path = Path.Combine(Repository.WorkingDirectory, hash);
                if (!rules.IgnoreFile(Repository.WorkingDirectory, path) && !rules.IgnoreDir(Repository.WorkingDirectory, path))
                {
                    UntrackedList.Add(hash);
                }
            }

            if (status.AnyDifferences || UntrackedList.Count > 0)
            {
                // Files use the following states: removed, missing, added, and modified.
                // If a file has been staged, it is also added to the RepositoryStatus.Staged HashSet.
                //
                // The remaining StatusType known as "Untracked" is determined by what is *not* staged or modified.
                // It is then intersected with the .gitignore list to determine what should be listed as untracked.
                // Using intersections will accurately display the "bucket" each file was added to.

                // Note: In standard git, they use cached references so the following scenario is possible.
                //    1) Filename = a.txt; StatusType=staged; FileState=added
                //    2) Filename = a.txt; StatusType=modified; FileState=added
                // Notice that the same filename exists in two separate status's because it points to a reference
                // Todo: This test has failed so far with this command.

                HashSet<string> stagedRemoved = new HashSet<string>(status.Staged);
                stagedRemoved.IntersectWith(status.Removed);
                HashSet<string> stagedMissing = new HashSet<string>(status.Staged);
                stagedMissing.IntersectWith(status.Missing);
                HashSet<string> stagedAdded = new HashSet<string>(status.Staged);
                stagedAdded.IntersectWith(status.Added);
                HashSet<string> stagedModified = new HashSet<string>(status.Staged);
                stagedModified.IntersectWith(status.Modified);
                stagedModified.ExceptWith(status.MergeConflict);

                HashSet<string> Removed = new HashSet<string>(status.Removed);
                Removed.ExceptWith(status.Staged);
                HashSet<string> Missing = new HashSet<string>(status.Missing);
                Missing.ExceptWith(status.Staged);
                HashSet<string> Added = new HashSet<string>(status.Added);
                Added.ExceptWith(status.Staged);
                HashSet<string> Modified = new HashSet<string>(status.Modified);
                Modified.ExceptWith(status.Staged);

                // The output below is used to display both where the file is being added and specifying the file.
                // Unit testing is still pending.
                /*OutputStream.WriteLine("# Staged Tests: StageType + status.Staged");
                OutputStream.WriteLine("# Staged Total: " + (stagedModified.Count + stagedRemoved.Count + stagedMissing.Count + stagedAdded.Count));
                OutputStream.WriteLine("# Test:     Modified Object Count: " + stagedModified.Count);
                OutputStream.WriteLine("# Test:      Removed Object Count: " + stagedRemoved.Count);
                OutputStream.WriteLine("# Test:      Missing Object Count: " + stagedMissing.Count);
                OutputStream.WriteLine("# Test:        Added Object Count: " + stagedAdded.Count);
                OutputStream.WriteLine("#");
                OutputStream.WriteLine("# Modified Tests: StageType w/o status.Staged");
                OutputStream.WriteLine("# Modified Total: " + (Modified.Count+Removed.Count+Missing.Count+Added.Count));
                OutputStream.WriteLine("# Test:      Changed Object Count: " + Modified.Count);
                OutputStream.WriteLine("# Test:      Removed Object Count: " + Removed.Count);
                OutputStream.WriteLine("# Test:      Missing Object Count: " + Missing.Count);
                OutputStream.WriteLine("# Test:        Added Object Count: " + Added.Count);
                OutputStream.WriteLine("#");
                OutputStream.WriteLine("# MergeConflict Tests: " + status.MergeConflict.Count);
                OutputStream.WriteLine("# Test:              Object Count: " + status.MergeConflict.Count);
                OutputStream.WriteLine("#");
                OutputStream.WriteLine("# UnTracked Tests: status.Untracked");
                OutputStream.WriteLine("# Test:    Untracked Object Count: " + status.Untracked.Count);
                OutputStream.WriteLine("# Test:      Ignored Object Count: Pending");
                OutputStream.WriteLine("#");*/

                //Display the stages of all files
                doDisplayMergeConflict(status);
                OutputStream.WriteLine("# On branch " + Repository.CurrentBranch.Name);
                //OutputStream.WriteLine("# Your branch is ahead of 'xxx' by x commits."); //Todo
                OutputStream.WriteLine("#");

                doDisplayStaged(status);
                doDisplayUnstaged(status);
                doDisplayUntracked(status);
                if (status.Staged.Count <= 0)
                {
                    OutputStream.WriteLine("no changes added to commit (use \"git add\" and/or \"git commit -a\")");
                }
            }
            else if (status.IndexSize <= 0)
            {
                OutputStream.WriteLine("# On branch " + Repository.CurrentBranch.Name);
                OutputStream.WriteLine("#");
                OutputStream.WriteLine("# Initial commit");
                OutputStream.WriteLine("#");
                OutputStream.WriteLine("# nothing to commit (create/copy files and use \"git add\" to track)");
            }
            else
            {
                OutputStream.WriteLine("# nothing to commit (working directory clean)");
            }
            //Leave this in until completed.
            throw new NotImplementedException("The implementation is not yet complete. autocrlf support is not added.");
        }
Exemplo n.º 5
0
        public override void Execute()
        {
            RepositoryStatus status = new RepositoryStatus(Repository);

            IgnoreRules rules;

            //Read ignore file list and remove from the untracked list
            try
            {
                rules = new IgnoreRules(Path.Combine(Repository.WorkingDirectory, ".gitignore"));
            }
            catch (FileNotFoundException)
            {
                //.gitignore file does not exist for a newly initialized repository.
                string[] lines = {};
                rules = new IgnoreRules(lines);
            }

            foreach (string hash in status.Untracked)
            {
                string path = Path.Combine(Repository.WorkingDirectory, hash);
                if (!rules.IgnoreFile(Repository.WorkingDirectory, path) && !rules.IgnoreDir(Repository.WorkingDirectory, path))
                {
                    results.UntrackedList.Add(hash);
                }
            }

            if (status.AnyDifferences || results.UntrackedList.Count > 0)
            {
                // Files use the following StatusTypes: removed, missing, added, and modified, modified w/staged, and merge conflict.
                // The following StatusStates are defined for each type:
                //              Modified -> Unstaged
                //         MergeConflict -> Unstaged
                //                 Added -> Staged
                //        ModifiedStaged -> Staged
                //               Removed -> Staged
                //               Missing -> Staged
                // The StatusState known as "Untracked" is determined by what is *not* defined in any state.
                // It is then intersected with the .gitignore list to determine what should be listed as untracked.

                HashSet <string> hset = new HashSet <string>(status.MergeConflict);
                foreach (string hash in hset)
                {
                    results.ModifiedList.Add(hash, StatusType.MergeConflict);
                    status.Staged.Remove(hash);
                    status.Modified.Remove(hash);
                }

                hset = new HashSet <string>(status.Missing);
                foreach (string hash in hset)
                {
                    results.ModifiedList.Add(hash, StatusType.Missing);
                }

                hset = new HashSet <string>(status.Modified);
                foreach (string hash in hset)
                {
                    results.ModifiedList.Add(hash, StatusType.Modified);
                }

                hset = new HashSet <string>(status.Staged);
                foreach (string hash in hset)
                {
                    results.StagedList.Add(hash, StatusType.ModifiedStaged);
                }

                hset = new HashSet <string>(status.Added);
                foreach (string hash in hset)
                {
                    results.StagedList.Add(hash, StatusType.Added);
                }

                hset = new HashSet <string>(status.Removed);
                foreach (string hash in hset)
                {
                    results.StagedList.Add(hash, StatusType.Removed);
                }

                results.UntrackedList.Sort();
                results.ModifiedList.OrderBy(v => v.Key);
                results.StagedList.OrderBy(v => v.Key);
            }

            IndexSize = Repository.Index.Size;
        }