Exemplo n.º 1
0
 protected internal FileViewModel(Repository repo, string path, string name, GitObject obj)
 {
     Repository = repo;
     Path       = path;
     Name       = name;
     Object     = obj;
 }
Exemplo n.º 2
0
        public Hash Put(GitObject obj)
        {
            var hash = obj.GetGitHash();

            _objects.TryAdd(hash, obj);
            return(hash);
        }
Exemplo n.º 3
0
        public void CanReadCommitData()
        {
            using (var repo = new Repository(Constants.BareTestRepoPath))
            {
                GitObject obj = repo.Lookup(sha);
                obj.ShouldNotBeNull();
                obj.GetType().ShouldEqual(typeof(Commit));

                var commit = (Commit)obj;
                commit.Message.ShouldEqual("testing\n");
                commit.MessageShort.ShouldEqual("testing");
                commit.Encoding.ShouldEqual("UTF-8");
                commit.Sha.ShouldEqual(sha);

                commit.Author.ShouldNotBeNull();
                commit.Author.Name.ShouldEqual("Scott Chacon");
                commit.Author.Email.ShouldEqual("*****@*****.**");
                commit.Author.When.ToSecondsSinceEpoch().ShouldEqual(1273360386);

                commit.Committer.ShouldNotBeNull();
                commit.Committer.Name.ShouldEqual("Scott Chacon");
                commit.Committer.Email.ShouldEqual("*****@*****.**");
                commit.Committer.When.ToSecondsSinceEpoch().ShouldEqual(1273360386);

                commit.Tree.Sha.ShouldEqual("181037049a54a1eb5fab404658a3a250b44335d7");

                commit.Parents.Count().ShouldEqual(0);
            }
        }
Exemplo n.º 4
0
        public override async Task ExecuteAsync()
        {
            Uri       imageInfoPathIdentifier = GitHelper.GetBlobUrl(Options.GitOptions);
            GitObject imageInfoGitObject      = await GetUpdatedImageInfoGitObjectAsync();

            if (imageInfoGitObject is null)
            {
                loggerService.WriteMessage($"No changes to the '{imageInfoPathIdentifier}' file were needed.");
                return;
            }

            loggerService.WriteMessage(
                $"The '{imageInfoPathIdentifier}' file has been updated with the following content:" +
                Environment.NewLine + imageInfoGitObject.Content + Environment.NewLine);

            if (!Options.IsDryRun)
            {
                using IGitHubClient gitHubClient = this.gitHubClientFactory.GetClient(Options.GitOptions.ToGitHubAuth(), Options.IsDryRun);
                await GitHelper.ExecuteGitOperationsWithRetryAsync(async() =>
                {
                    GitReference gitRef = await GitHelper.PushChangesAsync(
                        gitHubClient, Options, "Merging image info updates from build.",
                        branch => Task.FromResult <IEnumerable <GitObject> >(new GitObject[] { imageInfoGitObject }));

                    Uri commitUrl = GitHelper.GetCommitUrl(Options.GitOptions, gitRef.Object.Sha);
                    loggerService.WriteMessage($"The '{imageInfoPathIdentifier}' file was updated ({commitUrl}).");
                });
            }
        }
Exemplo n.º 5
0
        public void CanReadCommitData()
        {
            string path = SandboxBareTestRepo();

            using (var repo = new Repository(path))
            {
                GitObject obj = repo.Lookup(sha);
                Assert.NotNull(obj);
                Assert.Equal(typeof(Commit), obj.GetType());

                var commit = (Commit)obj;
                Assert.Equal("testing\n", commit.Message);
                Assert.Equal("testing", commit.MessageShort);
                Assert.Equal("UTF-8", commit.Encoding);
                Assert.Equal(sha, commit.Sha);

                Assert.NotNull(commit.Author);
                Assert.Equal("Scott Chacon", commit.Author.Name);
                Assert.Equal("*****@*****.**", commit.Author.Email);
                Assert.Equal(1273360386, commit.Author.When.ToSecondsSinceEpoch());

                Assert.NotNull(commit.Committer);
                Assert.Equal("Scott Chacon", commit.Committer.Name);
                Assert.Equal("*****@*****.**", commit.Committer.Email);
                Assert.Equal(1273360386, commit.Committer.When.ToSecondsSinceEpoch());

                Assert.Equal("181037049a54a1eb5fab404658a3a250b44335d7", commit.Tree.Sha);

                Assert.Equal(0, commit.Parents.Count());
            }
        }
Exemplo n.º 6
0
        public static Commit DereferenceToCommit(this GitObject gitObject, string identifier, bool throwsIfCanNotBeDereferencedToACommit)
        {
            if (gitObject == null && !throwsIfCanNotBeDereferencedToACommit)
            {
                return(null);
            }

            if (gitObject is Commit)
            {
                return((Commit)gitObject);
            }

            if (gitObject is TagAnnotation)
            {
                var target = ((TagAnnotation)gitObject).Target;
                return(target.DereferenceToCommit(identifier, throwsIfCanNotBeDereferencedToACommit));
            }

            if (!throwsIfCanNotBeDereferencedToACommit && (gitObject is Blob || gitObject is Tree))
            {
                return(null);
            }

            throw new LibGit2Exception(string.Format(CultureInfo.InvariantCulture,
                                                     "The Git object pointed at by '{0}' can not be dereferenced to a commit.",
                                                     identifier));
        }
Exemplo n.º 7
0
        public void CanLookupWhithShortIdentifers()
        {
            const string expectedAbbrevSha = "edfecad";
            const string expectedSha       = expectedAbbrevSha + "02d96c9dbf64f6e238c45ddcfa762eef0";

            SelfCleaningDirectory scd = BuildSelfCleaningDirectory();

            using (var repo = Repository.Init(scd.DirectoryPath))
            {
                string filePath = Path.Combine(repo.Info.WorkingDirectory, "new.txt");

                File.WriteAllText(filePath, "one ");
                repo.Index.Stage(filePath);

                Signature author = Constants.Signature;
                Commit    commit = repo.Commit("Initial commit", author, author);

                commit.Sha.ShouldEqual(expectedSha);

                GitObject lookedUp1 = repo.Lookup(expectedSha);
                lookedUp1.ShouldEqual(commit);

                GitObject lookedUp2 = repo.Lookup(expectedAbbrevSha);
                lookedUp2.ShouldEqual(commit);
            }
        }
Exemplo n.º 8
0
        public void CanLookupWhithShortIdentifers()
        {
            const string expectedAbbrevSha = "fe8410b";
            const string expectedSha       = expectedAbbrevSha + "6bfdf69ccfd4f397110d61f8070e46e40";

            string repoPath = InitNewRepository();

            using (var repo = new Repository(repoPath))
            {
                const string filename = "new.txt";
                Touch(repo.Info.WorkingDirectory, filename, "one ");
                repo.Stage(filename);

                Signature author = Constants.Signature;
                Commit    commit = repo.Commit("Initial commit", author, author);

                Assert.Equal(expectedSha, commit.Sha);

                GitObject lookedUp1 = repo.Lookup(expectedSha);
                Assert.Equal(commit, lookedUp1);

                GitObject lookedUp2 = repo.Lookup(expectedAbbrevSha);
                Assert.Equal(commit, lookedUp2);
            }
        }
Exemplo n.º 9
0
 protected internal FileViewModel(LibGit2Sharp.Repository repo, string path, string name, GitObject obj)
 {
     _repository = repo;
     _path       = path;
     _name       = name;
     _object     = obj;
 }
Exemplo n.º 10
0
        public void CanLookupWhithShortIdentifers()
        {
            const string expectedAbbrevSha = "fe8410b";
            const string expectedSha       = expectedAbbrevSha + "6bfdf69ccfd4f397110d61f8070e46e40";

            SelfCleaningDirectory scd = BuildSelfCleaningDirectory();

            using (var repo = Repository.Init(scd.DirectoryPath))
            {
                string filePath = Path.Combine(repo.Info.WorkingDirectory, "new.txt");

                File.WriteAllText(filePath, "one ");
                repo.Index.Stage(filePath);

                Signature author = Constants.Signature;
                Commit    commit = repo.Commit("Initial commit", author, author);

                Assert.Equal(expectedSha, commit.Sha);

                GitObject lookedUp1 = repo.Lookup(expectedSha);
                Assert.Equal(commit, lookedUp1);

                GitObject lookedUp2 = repo.Lookup(expectedAbbrevSha);
                Assert.Equal(commit, lookedUp2);
            }
        }
Exemplo n.º 11
0
        public override async ValueTask <TGitObject?> GetByIdAsync <TGitObject>(GitId id)
            where TGitObject : class
        {
            var name = id.ToString();

            string path = Path.Combine(_objectsDir, name.Substring(0, 2), name.Substring(2));

            if (!File.Exists(path))
            {
                return(null);
            }

            var fileReader = FileBucket.OpenRead(path, false);

            try
            {
                var rdr = new GitObjectFileBucket(fileReader);

                GitObject ob = await GitObject.FromBucketAsync(Repository, rdr, id).ConfigureAwait(false);

                if (ob is TGitObject tg)
                {
                    return(tg);
                }

                rdr.Dispose();

                return(null);
            }
            catch
            {
                fileReader.Dispose();
                throw;
            }
        }
Exemplo n.º 12
0
        private GitObject RewriteTarget(GitObject oldTarget)
        {
            // Has this target already been rewritten?
            if (objectMap.ContainsKey(oldTarget))
            {
                return(objectMap[oldTarget]);
            }

            Debug.Assert((oldTarget as Commit) == null);

            var annotation = oldTarget as TagAnnotation;

            if (annotation == null)
            {
                //TODO: Probably a Tree or a Blob. This is not covered by any test
                return(oldTarget);
            }

            // Recursively rewrite annotations if necessary
            var newTarget = RewriteTarget(annotation.Target);

            string newName = annotation.Name;

            if (options.TagNameRewriter != null)
            {
                newName = options.TagNameRewriter(annotation.Name, true, annotation.Target.Sha);
            }

            var newAnnotation = repo.ObjectDatabase.CreateTagAnnotation(newName, newTarget, annotation.Tagger,
                                                                        annotation.Message);

            objectMap[annotation] = newAnnotation;
            return(newAnnotation);
        }
Exemplo n.º 13
0
 public void TreeDataIsPresent()
 {
     using (var repo = new Repository(BareTestRepoPath))
     {
         GitObject tree = repo.Lookup(sha);
         Assert.NotNull(tree);
     }
 }
Exemplo n.º 14
0
 protected internal FileViewModel(Repository repo, string path, string name, GitObject obj, TreeEntryTargetType entryType)
 {
     Repository = repo;
     Path       = path;
     Name       = name;
     Object     = obj;
     EntryType  = entryType;
 }
Exemplo n.º 15
0
 public void TreeDataIsPresent()
 {
     using (var repo = new Repository(Constants.BareTestRepoPath))
     {
         GitObject tree = repo.Lookup(sha);
         tree.ShouldNotBeNull();
     }
 }
Exemplo n.º 16
0
 public void CanLookupATagAnnotationByTheNameOfAnAnnotatedTag()
 {
     using (var repo = new Repository(Constants.BareTestRepoPath))
     {
         GitObject gitObject = repo.Lookup("refs/tags/e90810b");
         gitObject.ShouldNotBeNull();
         Assert.IsInstanceOf <TagAnnotation>(gitObject);
     }
 }
Exemplo n.º 17
0
 public void CanLookupACommitByTheNameOfALightweightTag()
 {
     using (var repo = new Repository(BareTestRepoPath))
     {
         GitObject gitObject = repo.Lookup("refs/tags/lw");
         Assert.NotNull(gitObject);
         Assert.IsType <Commit>(gitObject);
     }
 }
Exemplo n.º 18
0
 public void CanLookupATagAnnotationByTheNameOfAnAnnotatedTag()
 {
     using (var repo = new Repository(BareTestRepoPath))
     {
         GitObject gitObject = repo.Lookup("refs/tags/e90810b");
         Assert.NotNull(gitObject);
         Assert.IsType <TagAnnotation>(gitObject);
     }
 }
Exemplo n.º 19
0
 public void CanLookupACommitByTheNameOfABranch()
 {
     using (var repo = new Repository(BareTestRepoPath))
     {
         GitObject gitObject = repo.Lookup("refs/heads/master");
         gitObject.ShouldNotBeNull();
         Assert.IsInstanceOf <Commit>(gitObject);
     }
 }
Exemplo n.º 20
0
 public void CanLookupACommitByTheNameOfALightweightTag()
 {
     using (var repo = new Repository(BareTestRepoPath))
     {
         GitObject gitObject = repo.Lookup("refs/tags/lw");
         gitObject.ShouldNotBeNull();
         Assert.IsInstanceOf <Commit>(gitObject);
     }
 }
Exemplo n.º 21
0
        public List <TreeEntryChanges> GetFilesChangedBetween(GitObject fromOldest, GitObject toNewest)
        {
            var commitFrom = _repo.Git.Lookup <Commit>(fromOldest.Sha);
            var commitTo   = _repo.Git.Lookup <Commit>(toNewest.Sha);

            var changes = _repo.Git.Diff.Compare <TreeChanges>(commitFrom.Tree, commitTo.Tree);

            return(FilterForProject(changes).ToList());
        }
Exemplo n.º 22
0
        static TreeEntry CreateTreeEntry(TreeEntryTargetType targetType, GitObject target, string path)
        {
            var treeEntry = Substitute.For <TreeEntry>();

            treeEntry.TargetType.Returns(targetType);
            treeEntry.Target.Returns(target);
            treeEntry.Path.Returns(path);
            return(treeEntry);
        }
Exemplo n.º 23
0
        private Tag CreateTag(GitObject commit, string name)
        {
            var tag = Substitute.For <Tag>();

            tag.Target.Returns(commit);
            tag.Name.Returns(name);
            tag.CanonicalName.Returns(name);
            return(tag);
        }
Exemplo n.º 24
0
 public void CanLookupACommitByTheNameOfABranch()
 {
     using (var repo = new Repository(BareTestRepoPath))
     {
         GitObject gitObject = repo.Lookup("refs/heads/master");
         Assert.NotNull(gitObject);
         Assert.IsType <Commit>(gitObject);
     }
 }
Exemplo n.º 25
0
 public void CanLookupObjectWithGeneric(string hex, ObjectType type)
 {
     using (Repository repo = SandboxRepository("testrepo"))
         using (GitObject o = repo.Objects.Lookup <GitObject>(new ObjectId(hex)))
         {
             Assert.NotNull(o);
             Assert.Equal(type, o.Type);
             Assert.Equal(new ObjectId(hex), o.Id);
         }
 }
Exemplo n.º 26
0
 static LiteralNodeObject convertToLiteralNodeObjectRecursive(GitObject gitObject)
 {
     if (gitObject is Tree gitTree)
     {
         return(new LiteralNodeObject
         {
             TreeContent =
                 gitTree.Select(treeEntry => (treeEntry.Name, convertToLiteralNodeObjectRecursive(treeEntry.Target)))
                 .ToImmutableList(),
         });
Exemplo n.º 27
0
 public void CanLookupSameObjectTwiceAndTheyAreEqual()
 {
     using (var repo = new Repository(Constants.BareTestRepoPath))
     {
         GitObject commit  = repo.Lookup(commitSha);
         GitObject commit2 = repo.Lookup(commitSha);
         commit.Equals(commit2).ShouldBeTrue();
         commit.GetHashCode().ShouldEqual(commit2.GetHashCode());
     }
 }
Exemplo n.º 28
0
        /// <summary>
        /// Follows the targets of a Git <see cref="Tag"/>.
        /// </summary>
        /// <param name="tag">Starting tag.</param>
        /// <returns>The tagged object.</returns>
        public static GitObject ResolveTarget(this Tag tag)
        {
            GitObject target = tag.Target;

            while (target is TagAnnotation)
            {
                target = ((TagAnnotation)(target)).Target;
            }
            return(target);
        }
Exemplo n.º 29
0
 public void CanLookupSameObjectTwiceAndTheyAreEqual()
 {
     using (var repo = new Repository(BareTestRepoPath))
     {
         GitObject commit  = repo.Lookup(commitSha);
         GitObject commit2 = repo.Lookup(commitSha);
         Assert.True(commit.Equals(commit2));
         Assert.Equal(commit2.GetHashCode(), commit.GetHashCode());
     }
 }
Exemplo n.º 30
0
        public void TreeDataIsPresent()
        {
            string path = SandboxBareTestRepo();

            using (var repo = new Repository(path))
            {
                GitObject tree = repo.Lookup(sha);
                Assert.NotNull(tree);
            }
        }
Exemplo n.º 31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SimpleEntry" /> struct.
 /// </summary>
 /// <param name="repo">The repo.</param>
 /// <param name="entry">The tree entry.</param>
 /// <exception cref="System.ArgumentNullException">
 /// repo
 /// or
 /// entry
 /// </exception>
 internal SimpleEntry(Repository repo, TreeEntry entry)
     : this()
 {
     if (repo == null) throw new ArgumentNullException("repo");
     if (entry == null) throw new ArgumentNullException("entry");
     this.repo = repo;
     this.entry = entry;
     target = entry.Target;
     this.blob = entry.Target as Blob;
     this.link = entry.Target as GitLink;
 }
Exemplo n.º 32
0
 public void RevParse(string revision, out Reference reference, out GitObject obj)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 33
0
        private ObjectId RewriteTarget(GitObject oldTarget)
        {
            // Has this target already been rewritten?
            if (shaMap.ContainsKey(oldTarget.Id))
            {
                return shaMap[oldTarget.Id];
            }

            Debug.Assert((oldTarget as Commit) == null);

            var annotation = oldTarget as TagAnnotation;
            if (annotation == null)
            {
                //TODO: Probably a Tree or a Blob. This is not covered by any test
                return oldTarget.Id;
            }

            // Recursively rewrite annotations if necessary
            ObjectId newTargetId = RewriteTarget(annotation.Target);

            var newTarget = repo.Lookup(newTargetId);

            string newName = annotation.Name;

            if (tagNameRewriter != null)
            {
                newName = tagNameRewriter(annotation.Name, true, annotation.Target);
            }

            var newAnnotation = repo.ObjectDatabase.CreateTagAnnotation(newName, newTarget, annotation.Tagger,
                                                              annotation.Message);
            shaMap[annotation.Id] = newAnnotation.Id;
            return newAnnotation.Id;
        }
Exemplo n.º 34
0
 public ObjectVertex(GitObject gitObject)
 {
     Sha = gitObject.Sha;
 }
Exemplo n.º 35
0
 private Tag CreateTag(GitObject commit, string name)
 {
     var tag = Substitute.For<Tag>();
     tag.Target.Returns(commit);
     tag.Name.Returns(name);
     tag.CanonicalName.Returns(name);
     return tag;
 }
Exemplo n.º 36
0
 public MockTag(string name, Commit target)
 {
     NameEx = name;
     TargetEx = target;
 }
Exemplo n.º 37
0
        /// <summary>
        ///   Inserts a <see cref = "TagAnnotation"/> into the object database, pointing to a specific <see cref = "GitObject"/>.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="target">The <see cref="GitObject"/> being pointed at.</param>
        /// <param name="tagger">The tagger.</param>
        /// <param name="message">The message.</param>
        /// <returns>The created <see cref = "Commit"/>.</returns>
        public virtual TagAnnotation CreateTag(string name, GitObject target, Signature tagger, string message)
        {
            string prettifiedMessage = Proxy.git_message_prettify(message);

            ObjectId tagId = Proxy.git_tag_annotation_create(repo.Handle, name, target, tagger, prettifiedMessage);

            return repo.Lookup<TagAnnotation>(tagId);
        }
Exemplo n.º 38
0
 public virtual TagAnnotation CreateTag(string name, GitObject target, Signature tagger, string message)
 {
     return CreateTagAnnotation(name, target, tagger, message);
 }
Exemplo n.º 39
0
        private int GetCommitsCountBetweenHeadAndCommit(Repository repository, GitObject target)
        {
            var filter = new CommitFilter();
            filter.Since = repository.Head.Commits.First();
            filter.Until = target;

            return repository.Commits.QueryBy(filter).Count();
        }