|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using LibGit2Sharp; |
| 4 | +using Microsoft.Extensions.Options; |
| 5 | + |
| 6 | +namespace GitVersion |
| 7 | +{ |
| 8 | + public class GitRepository : IRepository |
| 9 | + { |
| 10 | + private Lazy<IRepository> repositoryLazy; |
| 11 | + private IRepository repositoryInstance => repositoryLazy.Value; |
| 12 | + |
| 13 | + public GitRepository(IOptions<Arguments> options, IGitPreparer preparer) |
| 14 | + { |
| 15 | + repositoryLazy = new Lazy<IRepository>(() => InitRepository(options, preparer)); |
| 16 | + } |
| 17 | + |
| 18 | + private static IRepository InitRepository(IOptions<Arguments> options, IGitPreparer preparer) |
| 19 | + { |
| 20 | + preparer.Prepare(); //we need to prepare the repository before using it for version calculation |
| 21 | + return new Repository(options.Value.DotGitDirectory); |
| 22 | + } |
| 23 | + |
| 24 | + public void Dispose() |
| 25 | + { |
| 26 | + repositoryInstance.Dispose(); |
| 27 | + } |
| 28 | + |
| 29 | + public void Checkout(Tree tree, IEnumerable<string> paths, CheckoutOptions opts) |
| 30 | + { |
| 31 | + repositoryInstance.Checkout(tree, paths, opts); |
| 32 | + } |
| 33 | + |
| 34 | + public void CheckoutPaths(string committishOrBranchSpec, IEnumerable<string> paths, CheckoutOptions checkoutOptions) |
| 35 | + { |
| 36 | + repositoryInstance.CheckoutPaths(committishOrBranchSpec, paths, checkoutOptions); |
| 37 | + } |
| 38 | + |
| 39 | + public GitObject Lookup(ObjectId id) |
| 40 | + { |
| 41 | + return repositoryInstance.Lookup(id); |
| 42 | + } |
| 43 | + |
| 44 | + public GitObject Lookup(string objectish) |
| 45 | + { |
| 46 | + return repositoryInstance.Lookup(objectish); |
| 47 | + } |
| 48 | + |
| 49 | + public GitObject Lookup(ObjectId id, ObjectType type) |
| 50 | + { |
| 51 | + return repositoryInstance.Lookup(id, type); |
| 52 | + } |
| 53 | + |
| 54 | + public GitObject Lookup(string objectish, ObjectType type) |
| 55 | + { |
| 56 | + return repositoryInstance.Lookup(objectish, type); |
| 57 | + } |
| 58 | + |
| 59 | + public Commit Commit(string message, Signature author, Signature committer, CommitOptions options) |
| 60 | + { |
| 61 | + return repositoryInstance.Commit(message, author, committer, options); |
| 62 | + } |
| 63 | + |
| 64 | + public void Reset(ResetMode resetMode, Commit commit) |
| 65 | + { |
| 66 | + repositoryInstance.Reset(resetMode, commit); |
| 67 | + } |
| 68 | + |
| 69 | + public void Reset(ResetMode resetMode, Commit commit, CheckoutOptions options) |
| 70 | + { |
| 71 | + repositoryInstance.Reset(resetMode, commit, options); |
| 72 | + } |
| 73 | + |
| 74 | + public void RemoveUntrackedFiles() |
| 75 | + { |
| 76 | + repositoryInstance.RemoveUntrackedFiles(); |
| 77 | + } |
| 78 | + |
| 79 | + public RevertResult Revert(Commit commit, Signature reverter, RevertOptions options) |
| 80 | + { |
| 81 | + return repositoryInstance.Revert(commit, reverter, options); |
| 82 | + } |
| 83 | + |
| 84 | + public MergeResult Merge(Commit commit, Signature merger, MergeOptions options) |
| 85 | + { |
| 86 | + return repositoryInstance.Merge(commit, merger, options); |
| 87 | + } |
| 88 | + |
| 89 | + public MergeResult Merge(Branch branch, Signature merger, MergeOptions options) |
| 90 | + { |
| 91 | + return repositoryInstance.Merge(branch, merger, options); |
| 92 | + } |
| 93 | + |
| 94 | + public MergeResult Merge(string committish, Signature merger, MergeOptions options) |
| 95 | + { |
| 96 | + return repositoryInstance.Merge(committish, merger, options); |
| 97 | + } |
| 98 | + |
| 99 | + public MergeResult MergeFetchedRefs(Signature merger, MergeOptions options) |
| 100 | + { |
| 101 | + return repositoryInstance.MergeFetchedRefs(merger, options); |
| 102 | + } |
| 103 | + |
| 104 | + public CherryPickResult CherryPick(Commit commit, Signature committer, CherryPickOptions options) |
| 105 | + { |
| 106 | + return repositoryInstance.CherryPick(commit, committer, options); |
| 107 | + } |
| 108 | + |
| 109 | + public BlameHunkCollection Blame(string path, BlameOptions options) |
| 110 | + { |
| 111 | + return repositoryInstance.Blame(path, options); |
| 112 | + } |
| 113 | + |
| 114 | + public FileStatus RetrieveStatus(string filePath) |
| 115 | + { |
| 116 | + return repositoryInstance.RetrieveStatus(filePath); |
| 117 | + } |
| 118 | + |
| 119 | + public RepositoryStatus RetrieveStatus(StatusOptions options) |
| 120 | + { |
| 121 | + return repositoryInstance.RetrieveStatus(options); |
| 122 | + } |
| 123 | + |
| 124 | + public string Describe(Commit commit, DescribeOptions options) |
| 125 | + { |
| 126 | + return repositoryInstance.Describe(commit, options); |
| 127 | + } |
| 128 | + |
| 129 | + public void RevParse(string revision, out Reference reference, out GitObject obj) |
| 130 | + { |
| 131 | + repositoryInstance.RevParse(revision, out reference, out obj); |
| 132 | + } |
| 133 | + |
| 134 | + public Branch Head => repositoryInstance.Head; |
| 135 | + |
| 136 | + public LibGit2Sharp.Configuration Config => repositoryInstance.Config; |
| 137 | + |
| 138 | + public Index Index => repositoryInstance.Index; |
| 139 | + |
| 140 | + public ReferenceCollection Refs => repositoryInstance.Refs; |
| 141 | + |
| 142 | + public IQueryableCommitLog Commits => repositoryInstance.Commits; |
| 143 | + |
| 144 | + public BranchCollection Branches => repositoryInstance.Branches; |
| 145 | + |
| 146 | + public TagCollection Tags => repositoryInstance.Tags; |
| 147 | + |
| 148 | + public RepositoryInformation Info => repositoryInstance.Info; |
| 149 | + |
| 150 | + public Diff Diff => repositoryInstance.Diff; |
| 151 | + |
| 152 | + public ObjectDatabase ObjectDatabase => repositoryInstance.ObjectDatabase; |
| 153 | + |
| 154 | + public NoteCollection Notes => repositoryInstance.Notes; |
| 155 | + |
| 156 | + public SubmoduleCollection Submodules => repositoryInstance.Submodules; |
| 157 | + |
| 158 | + public WorktreeCollection Worktrees => repositoryInstance.Worktrees; |
| 159 | + |
| 160 | + public Rebase Rebase => repositoryInstance.Rebase; |
| 161 | + |
| 162 | + public Ignore Ignore => repositoryInstance.Ignore; |
| 163 | + |
| 164 | + public Network Network => repositoryInstance.Network; |
| 165 | + |
| 166 | + public StashCollection Stashes => repositoryInstance.Stashes; |
| 167 | + } |
| 168 | +} |
0 commit comments