Exemplo n.º 1
0
        public void CommitInNewBranch()
        {
            Init();

            CreateFile("z.txt", "");
            Program.Main(new string[] { "add", "z.txt" });
            Program.Main(new string[] { "commit", "Initial commit" });
            Program.Main(new string[] { "branch", "branch-1" });
            Program.Main(new string[] { "checkout", "branch-1" });

            // Create a commit in branch-1
            CreateFile("a.txt", "branch-1 content");
            Program.Main(new string[] { "add", "a.txt" });
            Program.Main(new string[] { "commit", "branch-1 commit" });

            Assert.Equal(
                ReferenceDatabase.GetHead().GetCommitKey(),
                ReferenceDatabase.GetBranch("branch-1").GetCommitKey()
                );

            Assert.Equal(
                ReferenceDatabase.GetBranch("branch-1").LoadCommit().Message.Trim(),
                "branch-1 commit"
                );
        }
Exemplo n.º 2
0
        public void CreateOneBranchAfterCommitTest()
        {
            Init();

            CreateFile("a.txt", "a content");
            Program.Main(new string[] { "add", "a.txt" });
            Program.Main(new string[] { "commit", "First commit" });
            Program.Main(new string[] { "branch", "new-branch" });

            Branch headBranch = ReferenceDatabase.GetHead();

            Assert.Equal(headBranch.Name, "master");
            Branch newBranch = ReferenceDatabase.GetBranch("new-branch");

            Assert.Equal(headBranch.GetCommitKey(), newBranch.GetCommitKey());
        }
Exemplo n.º 3
0
        private bool ProcessArgs()
        {
            if (_args.Length != 1)
            {
                PrintHelp();
                return(false);
            }

            _branch = ReferenceDatabase.GetBranch(_args[0]);
            if (_branch == null)
            {
                Console.WriteLine($"{_args[0]} does not specify any branch name");
                return(false);
            }

            return(true);
        }