public void BlindlyMovingABranchOverAnExistingOneThrows()
 {
     using (var path = new TemporaryCloneOfTestRepo())
     using (var repo = new Repository(path.RepositoryPath))
     {
         Assert.Throws<ApplicationException>(() => repo.Branches.Move("br2", "test"));
     }
 }
 public void BlindlyCreatingALightweightTagOverAnExistingOneThrows()
 {
     using (var path = new TemporaryCloneOfTestRepo())
     using (var repo = new Repository(path.RepositoryPath))
     {
         Assert.Throws<ApplicationException>(() => repo.Tags.Create("e90810b", "refs/heads/br2"));
     }
 }
 public void BlindlyCreatingAnAnnotatedTagOverAnExistingOneThrows()
 {
     using (var path = new TemporaryCloneOfTestRepo())
     using (var repo = new Repository(path.RepositoryPath))
     {
         Assert.Throws<ApplicationException>(() => repo.Tags.Create("e90810b", "refs/heads/br2", signatureNtk, "a nice message"));
     }
 }
 public void BlindlyCreatingADirectReferenceOverAnExistingOneThrows()
 {
     using (var path = new TemporaryCloneOfTestRepo())
     using (var repo = new Repository(path.RepositoryPath))
     {
         Assert.Throws<ApplicationException>(() => repo.Refs.Create("refs/heads/master", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
     }
 }
 public void BlindlyCreatingASymbolicReferenceOverAnExistingOneThrows()
 {
     using (var path = new TemporaryCloneOfTestRepo())
     using (var repo = new Repository(path.RepositoryPath))
     {
         Assert.Throws<ApplicationException>(() => repo.Refs.Create("HEAD", "refs/head/br2"));
     }
 }
 public void CanCreateALightweightTagFromABranchName()
 {
     using (var path = new TemporaryCloneOfTestRepo())
     using (var repo = new Repository(path.RepositoryPath))
     {
         var newTag = repo.Tags.Create("i_am_lightweight", "refs/heads/master");
         newTag.IsAnnotated.ShouldBeFalse();
         newTag.ShouldNotBeNull();
     }
 }
 public void CanCreateALightWeightTagFromAbbreviatedSha()
 {
     using (var path = new TemporaryCloneOfTestRepo())
     using (var repo = new Repository(path.RepositoryPath))
     {
         var newTag = repo.Tags.Create("i_am_lightweight", commitE90810BSha.Substring(0, 17));
         newTag.ShouldNotBeNull();
         newTag.IsAnnotated.ShouldBeFalse();
     }
 }
        public void ADeletedTagCannotBeLookedUp()
        {
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                const string tagName = "e90810b";

                repo.Tags.Delete(tagName);
                repo.Tags[tagName].ShouldBeNull();
            }
        }
        public void ADeletedReferenceCannotBeLookedUp()
        {
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                const string refName = "refs/heads/test";

                repo.Refs.Delete(refName);
                repo.Refs[refName].ShouldBeNull();
            }
        }
 public void CanCreateBranchFromExplicitHead()
 {
     using (var path = new TemporaryCloneOfTestRepo())
     using (var repo = new Repository(path.RepositoryPath))
     {
         const string name = "unit_test";
         var newBranch = repo.CreateBranch(name, "HEAD");
         newBranch.ShouldNotBeNull();
         newBranch.Tip.Sha.ShouldEqual("4c062a6361ae6959e06292c1fa5e2822d9c96345");
     }
 }
        public void CanCheckoutAnExistingBranch()
        {
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                var master = repo.Branches["master"];
                master.IsCurrentRepositoryHead.ShouldBeTrue();

                var test = repo.Branches.Checkout("test");

                test.IsCurrentRepositoryHead.ShouldBeTrue();
                master.IsCurrentRepositoryHead.ShouldBeFalse();
            }
        }
        public void CanCreateADirectReference()
        {
            const string name = "refs/heads/unit_test";

            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                var newRef = (DirectReference) repo.Refs.Create(name, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
                newRef.ShouldNotBeNull();
                newRef.CanonicalName.ShouldEqual(name);
                newRef.Target.ShouldNotBeNull();
                newRef.Target.Sha.ShouldEqual("be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
                newRef.TargetIdentifier.ShouldEqual(newRef.Target.Sha);
                repo.Refs[name].ShouldNotBeNull();
            }
        }
 public void CanCreateBranchFromImplicitHead()
 {
     using (var path = new TemporaryCloneOfTestRepo())
     using (var repo = new Repository(path.RepositoryPath))
     {
         const string name = "unit_test";
         var newBranch = repo.CreateBranch(name);
         newBranch.ShouldNotBeNull();
         newBranch.Name.ShouldEqual(name);
         newBranch.CanonicalName.ShouldEqual("refs/heads/" + name);
         newBranch.IsCurrentRepositoryHead.ShouldBeFalse();
         newBranch.Tip.ShouldNotBeNull();
         newBranch.Tip.Sha.ShouldEqual("4c062a6361ae6959e06292c1fa5e2822d9c96345");
         repo.Branches.SingleOrDefault(p => p.Name == name).ShouldNotBeNull();
     }
 }
        public void CanCreateBranch()
        {
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                const string name = "unit_test";
                var newBranch = repo.CreateBranch(name, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
                newBranch.ShouldNotBeNull();
                newBranch.Name.ShouldEqual(name);
                newBranch.CanonicalName.ShouldEqual("refs/heads/" + name);
                newBranch.Tip.ShouldNotBeNull();
                newBranch.Tip.Sha.ShouldEqual("be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
                repo.Branches.SingleOrDefault(p => p.Name == name).ShouldNotBeNull();

                repo.Branches.Delete(newBranch.Name);
            }
        }
        public void TwoBranchesPointingAtTheSameCommitAreNotBothCurrent()
        {
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                var master = repo.Branches["refs/heads/master"];

                var newBranch = repo.Branches.Create("clone-of-master", master.Tip.Sha);
                newBranch.IsCurrentRepositoryHead.ShouldBeFalse();
            }
        }
        public void CanUpdateTargetOnReference()
        {
            const string masterRef = "refs/heads/master";
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                var sha = repo.Refs["refs/heads/test"].ResolveToDirectReference().Target.Sha;
                var master = repo.Refs[masterRef];
                master.ResolveToDirectReference().Target.Sha.ShouldNotEqual(sha);

                var updated = repo.Refs.UpdateTarget(masterRef, sha);

                master = repo.Refs[masterRef];
                master.ShouldEqual(updated);

                master.ResolveToDirectReference().Target.Sha.ShouldEqual(sha);
            }
        }
 public void DeletingBranchWithBadParamsThrows()
 {
     using (var path = new TemporaryCloneOfTestRepo())
     using (var repo = new Repository(path.RepositoryPath))
     {
         Assert.Throws<ArgumentException>(() => repo.Branches.Delete(string.Empty));
         Assert.Throws<ArgumentNullException>(() => repo.Branches.Delete(null));
     }
 }
        public void CreatingABranchTriggersTheCreationOfADirectReference()
        {
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                var newBranch = repo.CreateBranch("clone-of-master");
                newBranch.IsCurrentRepositoryHead.ShouldBeFalse();

                var commitId = repo.Head.Tip.Id;
                newBranch.Tip.Id.ShouldEqual(commitId);

                var reference = repo.Refs[newBranch.CanonicalName];
                reference.ShouldNotBeNull();
                Assert.IsInstanceOf(typeof (DirectReference), reference);
            }
        }
        public void CanLookupAMovedReference()
        {
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                const string oldName = "refs/tags/test";
                const string newName = "refs/atic/tagtest";

                Reference moved = repo.Refs.Move(oldName, newName);

                Reference lookedUp = repo.Refs[newName];
                moved.ShouldEqual(lookedUp);
            }
        }
        public void CanMoveABranchWhileOverwritingAnExistingOne()
        {
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                var test = repo.Branches["test"];
                test.ShouldNotBeNull();

                var br2 = repo.Branches["br2"];
                br2.ShouldNotBeNull();

                var newBranch = repo.Branches.Move("br2", "test", true);
                newBranch.Name.ShouldEqual("test");

                repo.Branches["br2"].ShouldBeNull();

                var newTest = repo.Branches["test"];
                newTest.ShouldNotBeNull();
                newTest.ShouldEqual(newBranch);

                newTest.Tip.ShouldEqual(br2.Tip);
            }
        }
        public void CanUpdateTargetOnSymbolicReference()
        {
            const string name = "refs/heads/unit_test";
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                var newRef = (SymbolicReference) repo.Refs.Create(name, "refs/heads/master");
                newRef.ShouldNotBeNull();

                repo.Refs.UpdateTarget(newRef.CanonicalName, "refs/heads/test");

                newRef = (SymbolicReference) repo.Refs[newRef.CanonicalName];
                newRef.ResolveToDirectReference().Target.ShouldEqual(repo.Refs["refs/heads/test"].ResolveToDirectReference().Target);

                repo.Refs.Delete(newRef.CanonicalName);
            }
        }
        public void UpdatingADirectRefWithSymbolFails()
        {
            const string name = "refs/heads/unit_test";
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                var newRef = (SymbolicReference) repo.Refs.Create(name, "refs/heads/master");
                newRef.ShouldNotBeNull();

                Assert.Throws<ArgumentException>(
                    () => repo.Refs.UpdateTarget(newRef.CanonicalName, repo.Refs["refs/heads/test"].ResolveToDirectReference().Target.Sha));

                repo.Refs.Delete(newRef.CanonicalName);
            }
        }
        public void CanMoveAndOverWriteAExistingReference()
        {
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                const string oldName = "refs/heads/packed";
                const string newName = "refs/heads/br2";

                Reference moved = repo.Refs.Move(oldName, newName, true);

                repo.Refs[oldName].ShouldBeNull();
                repo.Refs[moved.CanonicalName].ShouldNotBeNull();
            }
        }
        public void MovingAReferenceDoesNotDecreaseTheRefsCount()
        {
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                const string oldName = "refs/tags/test";
                const string newName = "refs/atic/tagtest";

                var refs = repo.Refs.Select(r => r.CanonicalName).ToList();
                refs.Contains(oldName).ShouldBeTrue();

                repo.Refs.Move(oldName, newName);

                var refs2 = repo.Refs.Select(r => r.CanonicalName).ToList();
                refs2.Contains(oldName).ShouldBeFalse();
                refs2.Contains(newName).ShouldBeTrue();

                refs.Count.ShouldEqual(refs2.Count);
            }
        }
        public void DeletingAReferenceDecreasesTheRefsCount()
        {
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                const string refName = "refs/heads/test";

                var refs = repo.Refs.Select(r => r.CanonicalName).ToList();
                refs.Contains(refName).ShouldBeTrue();

                repo.Refs.Delete(refName);

                var refs2 = repo.Refs.Select(r => r.CanonicalName).ToList();
                refs2.Contains(refName).ShouldBeFalse();

                refs2.Count.ShouldEqual(refs.Count - 1);
            }
        }
        public void CanMoveAReferenceToADifferentReferenceHierarchy()
        {
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                const string newName = "refs/atic/tagtest";

                Reference moved = repo.Refs.Move("refs/tags/test", newName);
                moved.ShouldNotBeNull();
                moved.CanonicalName.ShouldEqual(newName);
            }
        }
        public void CanCreateAndOverwriteADirectReference()
        {
            const string name = "refs/heads/br2";
            const string target = "4c062a6361ae6959e06292c1fa5e2822d9c96345";

            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                var newRef = (DirectReference)repo.Refs.Create(name, target, true);
                newRef.ShouldNotBeNull();
                newRef.CanonicalName.ShouldEqual(name);
                newRef.Target.ShouldNotBeNull();
                newRef.Target.Sha.ShouldEqual(target);
                ((DirectReference)repo.Refs[name]).Target.Sha.ShouldEqual(target);
            }
        }
        public void CanMoveABranch()
        {
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                repo.Branches["br3"].ShouldBeNull();

                var newBranch = repo.Branches.Move("br2", "br3");
                newBranch.Name.ShouldEqual("br3");

                repo.Branches["br2"].ShouldBeNull();
                repo.Branches["br3"].ShouldNotBeNull();
            }
        }
 public void CanCreateBranchUsingAbbreviatedSha()
 {
     using (var path = new TemporaryCloneOfTestRepo())
     using (var repo = new Repository(path.RepositoryPath))
     {
         const string name = "unit_test";
         var newBranch = repo.CreateBranch(name, "be3563a");
         newBranch.CanonicalName.ShouldEqual("refs/heads/" + name);
         newBranch.Tip.Sha.ShouldEqual("be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
     }
 }
        public void CanMoveAReferenceToAUpperReferenceHierarchy()
        {
            using (var path = new TemporaryCloneOfTestRepo())
            using (var repo = new Repository(path.RepositoryPath))
            {
                const string newName = "refs/heads/o/sole";
                const string oldName = newName + "/mio";

                repo.Refs.Create(oldName, repo.Head.CanonicalName);
                Reference moved = repo.Refs.Move(oldName, newName);
                moved.ShouldNotBeNull();
                moved.CanonicalName.ShouldEqual(newName);
            }
        }