protected internal FileViewModel(Repository repo, string path, string name, GitObject obj) { Repository = repo; Path = path; Name = name; Object = obj; }
public Hash Put(GitObject obj) { var hash = obj.GetGitHash(); _objects.TryAdd(hash, obj); return(hash); }
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); } }
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})."); }); } }
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()); } }
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)); }
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); } }
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); } }
protected internal FileViewModel(LibGit2Sharp.Repository repo, string path, string name, GitObject obj) { _repository = repo; _path = path; _name = name; _object = obj; }
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); } }
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; } }
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); }
public void TreeDataIsPresent() { using (var repo = new Repository(BareTestRepoPath)) { GitObject tree = repo.Lookup(sha); Assert.NotNull(tree); } }
protected internal FileViewModel(Repository repo, string path, string name, GitObject obj, TreeEntryTargetType entryType) { Repository = repo; Path = path; Name = name; Object = obj; EntryType = entryType; }
public void TreeDataIsPresent() { using (var repo = new Repository(Constants.BareTestRepoPath)) { GitObject tree = repo.Lookup(sha); tree.ShouldNotBeNull(); } }
public void CanLookupATagAnnotationByTheNameOfAnAnnotatedTag() { using (var repo = new Repository(Constants.BareTestRepoPath)) { GitObject gitObject = repo.Lookup("refs/tags/e90810b"); gitObject.ShouldNotBeNull(); Assert.IsInstanceOf <TagAnnotation>(gitObject); } }
public void CanLookupACommitByTheNameOfALightweightTag() { using (var repo = new Repository(BareTestRepoPath)) { GitObject gitObject = repo.Lookup("refs/tags/lw"); Assert.NotNull(gitObject); Assert.IsType <Commit>(gitObject); } }
public void CanLookupATagAnnotationByTheNameOfAnAnnotatedTag() { using (var repo = new Repository(BareTestRepoPath)) { GitObject gitObject = repo.Lookup("refs/tags/e90810b"); Assert.NotNull(gitObject); Assert.IsType <TagAnnotation>(gitObject); } }
public void CanLookupACommitByTheNameOfABranch() { using (var repo = new Repository(BareTestRepoPath)) { GitObject gitObject = repo.Lookup("refs/heads/master"); gitObject.ShouldNotBeNull(); Assert.IsInstanceOf <Commit>(gitObject); } }
public void CanLookupACommitByTheNameOfALightweightTag() { using (var repo = new Repository(BareTestRepoPath)) { GitObject gitObject = repo.Lookup("refs/tags/lw"); gitObject.ShouldNotBeNull(); Assert.IsInstanceOf <Commit>(gitObject); } }
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()); }
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); }
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); }
public void CanLookupACommitByTheNameOfABranch() { using (var repo = new Repository(BareTestRepoPath)) { GitObject gitObject = repo.Lookup("refs/heads/master"); Assert.NotNull(gitObject); Assert.IsType <Commit>(gitObject); } }
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); } }
static LiteralNodeObject convertToLiteralNodeObjectRecursive(GitObject gitObject) { if (gitObject is Tree gitTree) { return(new LiteralNodeObject { TreeContent = gitTree.Select(treeEntry => (treeEntry.Name, convertToLiteralNodeObjectRecursive(treeEntry.Target))) .ToImmutableList(), });
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()); } }
/// <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); }
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()); } }
public void TreeDataIsPresent() { string path = SandboxBareTestRepo(); using (var repo = new Repository(path)) { GitObject tree = repo.Lookup(sha); Assert.NotNull(tree); } }
/// <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; }
public void RevParse(string revision, out Reference reference, out GitObject obj) { throw new NotImplementedException(); }
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; }
public ObjectVertex(GitObject gitObject) { Sha = gitObject.Sha; }
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; }
public MockTag(string name, Commit target) { NameEx = name; TargetEx = target; }
/// <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); }
public virtual TagAnnotation CreateTag(string name, GitObject target, Signature tagger, string message) { return CreateTagAnnotation(name, target, tagger, message); }
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(); }