コード例 #1
0
ファイル: FileViewModel.cs プロジェクト: weikety/GitDC
 protected internal FileViewModel(Repository repo, string path, string name, GitObject obj)
 {
     Repository = repo;
     Path       = path;
     Name       = name;
     Object     = obj;
 }
コード例 #2
0
        public Hash Put(GitObject obj)
        {
            var hash = obj.GetGitHash();

            _objects.TryAdd(hash, obj);
            return(hash);
        }
コード例 #3
0
ファイル: CommitFixture.cs プロジェクト: tclem/libgit2sharp
        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);
            }
        }
コード例 #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}).");
                });
            }
        }
コード例 #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());
            }
        }
コード例 #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));
        }
コード例 #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);
            }
        }
コード例 #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);
            }
        }
コード例 #9
0
ファイル: FileViewModel.cs プロジェクト: maikebing/Giti
 protected internal FileViewModel(LibGit2Sharp.Repository repo, string path, string name, GitObject obj)
 {
     _repository = repo;
     _path       = path;
     _name       = name;
     _object     = obj;
 }
コード例 #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);
            }
        }
コード例 #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;
            }
        }
コード例 #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);
        }
コード例 #13
0
 public void TreeDataIsPresent()
 {
     using (var repo = new Repository(BareTestRepoPath))
     {
         GitObject tree = repo.Lookup(sha);
         Assert.NotNull(tree);
     }
 }
コード例 #14
0
ファイル: FileViewModel.cs プロジェクト: weikety/GitDC
 protected internal FileViewModel(Repository repo, string path, string name, GitObject obj, TreeEntryTargetType entryType)
 {
     Repository = repo;
     Path       = path;
     Name       = name;
     Object     = obj;
     EntryType  = entryType;
 }
コード例 #15
0
ファイル: TreeFixture.cs プロジェクト: tclem/libgit2sharp
 public void TreeDataIsPresent()
 {
     using (var repo = new Repository(Constants.BareTestRepoPath))
     {
         GitObject tree = repo.Lookup(sha);
         tree.ShouldNotBeNull();
     }
 }
コード例 #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);
     }
 }
コード例 #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);
     }
 }
コード例 #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);
     }
 }
コード例 #19
0
 public void CanLookupACommitByTheNameOfABranch()
 {
     using (var repo = new Repository(BareTestRepoPath))
     {
         GitObject gitObject = repo.Lookup("refs/heads/master");
         gitObject.ShouldNotBeNull();
         Assert.IsInstanceOf <Commit>(gitObject);
     }
 }
コード例 #20
0
 public void CanLookupACommitByTheNameOfALightweightTag()
 {
     using (var repo = new Repository(BareTestRepoPath))
     {
         GitObject gitObject = repo.Lookup("refs/tags/lw");
         gitObject.ShouldNotBeNull();
         Assert.IsInstanceOf <Commit>(gitObject);
     }
 }
コード例 #21
0
ファイル: Project.cs プロジェクト: drewburlingame/mrGitTags
        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());
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
     }
 }
コード例 #25
0
ファイル: ObjectTests.cs プロジェクト: mjcheetham/dogged
 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);
         }
 }
コード例 #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(),
         });
コード例 #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());
     }
 }
コード例 #28
0
ファイル: GitExtensions.cs プロジェクト: bcrosnier/SGV-Net
        /// <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);
        }
コード例 #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());
     }
 }
コード例 #30
0
        public void TreeDataIsPresent()
        {
            string path = SandboxBareTestRepo();

            using (var repo = new Repository(path))
            {
                GitObject tree = repo.Lookup(sha);
                Assert.NotNull(tree);
            }
        }
コード例 #31
0
ファイル: SimpleEntry.cs プロジェクト: xoofx/GitRocketFilter
 /// <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;
 }
コード例 #32
0
ファイル: MockRepository.cs プロジェクト: asbjornu/GitVersion
 public void RevParse(string revision, out Reference reference, out GitObject obj)
 {
     throw new NotImplementedException();
 }
コード例 #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;
        }
コード例 #34
0
ファイル: ObjectVertex.cs プロジェクト: g0t4/SeeGit
 public ObjectVertex(GitObject gitObject)
 {
     Sha = gitObject.Sha;
 }
コード例 #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;
 }
コード例 #36
0
ファイル: MockTag.cs プロジェクト: qetza/GitVersion
 public MockTag(string name, Commit target)
 {
     NameEx = name;
     TargetEx = target;
 }
コード例 #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);
        }
コード例 #38
0
ファイル: ObjectDatabase.cs プロジェクト: JenekX/libgit2sharp
 public virtual TagAnnotation CreateTag(string name, GitObject target, Signature tagger, string message)
 {
     return CreateTagAnnotation(name, target, tagger, message);
 }
コード例 #39
0
ファイル: GitDescribe.cs プロジェクト: Bitrete/msbuildtasks
        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();
        }