本文整理汇总了C#中LibGit2Sharp.Repository类的典型用法代码示例。如果您正苦于以下问题:C# Repository类的具体用法?C# Repository怎么用?C# Repository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Repository类属于LibGit2Sharp命名空间,在下文中一共展示了Repository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
{
var repositoryLocation = Repository.Discover(context.InputFolder);
if (repositoryLocation == null)
throw new ArgumentException("No git repository found");
using (Repository repository = new Repository(repositoryLocation))
{
var data = GetCommitInformation(repository);
var lookup = data.ToLookup(x => x.Path.ToLower());
return inputs.Select(x =>
{
string relativePath = GetRelativePath(Path.GetDirectoryName(Path.GetDirectoryName(repositoryLocation.ToLower())), x.Source.ToLower()); // yes we need to do it twice
if (!lookup.Contains(relativePath))
return x;
var commitsOfFile = lookup[relativePath]
.GroupBy(y => y.Author)
.ToDictionary(y => y.Key,
y => y.OrderByDescending(z => z.AuthorDateTime).First())
.Select(y => y.Value)
.ToArray();
return x.Clone(new[]
{
new KeyValuePair<string, object>(_metadataName, commitsOfFile)
});
}).ToArray(); // Don't do it lazy or Commit is disposed.
}
}
示例2: RepositoryWriter
RepositoryWriter( Repository r, string userName = null, string userEmail = null )
{
if( (userEmail == null) != (userName== null ) ) throw new ArgumentException();
_repo = r;
_userEmail = userEmail;
_userName = userName;
}
示例3: ContentChanges
internal ContentChanges(Repository repo, Blob oldBlob, Blob newBlob, GitDiffOptions options)
{
Proxy.git_diff_blobs(repo.Handle,
oldBlob != null ? oldBlob.Id : null,
newBlob != null ? newBlob.Id : null,
options, FileCallback, HunkCallback, LineCallback);
}
示例4: PersistentInfo
public PersistentInfo( Repository r )
: this()
{
if( r == null ) RepositoryError = "No repository.";
else
{
var branch = r.Head;
if( branch.Tip == null ) RepositoryError = "Unitialized repository.";
else
{
CommitSha = branch.Tip.Sha;
var repositoryStatus = r.Index.RetrieveStatus();
IsDirty = repositoryStatus.Added.Any()
|| repositoryStatus.Missing.Any()
|| repositoryStatus.Modified.Any()
|| repositoryStatus.Removed.Any()
|| repositoryStatus.Staged.Any();
ReleasedTag = FindReleasedVersion( r, branch.Tip );
if( ReleasedTag.IsValid )
{
BranchName = ReleasedTag.BranchName;
}
else
{
BranchName = branch.Name;
}
}
}
}
示例5: HashWithLibGit2Sharp
private static string HashWithLibGit2Sharp(Stream file)
{
var repository = new Repository(Environment.CurrentDirectory);
var temp = new FileStream(Path.GetTempFileName(),FileMode.Open);
file.CopyTo(temp);
return repository.ObjectDatabase.CreateBlob(temp.Name).Sha.ToString();
}
示例6: ObjectDatabase
internal ObjectDatabase(Repository repo)
{
this.repo = repo;
handle = Proxy.git_repository_odb(repo.Handle);
repo.RegisterForCleanup(handle);
}
示例7: Main
static void Main(string[] args)
{
string ruta = @"C:\Users\developer\Documents\GitHub\libgit2sharp";
var repo = new Repository(ruta);
//Listar(repo);
int numCommits = 0;
int programadores = 8;
int años = 2014 - 2010; //desde 2010
Console.WriteLine("Numero de commits por branch:");
foreach (var rama in repo.Branches)
{
Console.WriteLine("Rama: " + rama.Name + " tiene " + rama.Commits.Count() + " commits");
numCommits += rama.Commits.Count();
}
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine("\r\nRamas listadas " + repo.Branches.Count());
Console.WriteLine("Total commits: " + numCommits);
float lineas = ((numCommits/programadores)/(años*365));
Console.WriteLine("Lineas media por dia: " + lineas);
//ObtenerComits(repo);
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.Write("\r\nFin");
Console.Read();
}
示例8: GetConfig
/// <summary>
/// Get the git configuration
/// </summary>
/// <returns>A Config object.</returns>
public Config GetConfig()
{
//Run at startup, this will create the global repository, only needs to be run once.
Repository.Init(GlobalGitRepositoryLocation, true);
//Run at startup, this will create the instance specific clone on the local machine, should be run on every service start.
//Don't need to do this more than once the first time
if (!Repository.IsValid(LocalGitRepositoryLocation)) { Repository.Clone(GlobalGitRepositoryLocation, LocalGitRepositoryLocation, new CloneOptions { IsBare = true }); }
//In application code attempt to use the git repository
using (var repository = new Repository(LocalGitRepositoryLocation))
{
try { repository.Network.Fetch(repository.Network.Remotes[ConfigurationRemote]); } catch { }
var refOriginMaster = repository.Refs[ConfigurationRemoteRef];
if (refOriginMaster == null) { return new Config(); }
var sha = refOriginMaster.TargetIdentifier;
var configFile = repository.Lookup<Commit>(sha)[GitConfigurationFile];
if (configFile == null || !(configFile.Target is Blob)) { return new Config(); }
using (var fileStream = ((Blob)configFile.Target).GetContentStream())
using (var reader = new StreamReader(fileStream, Encoding.UTF8))
{
var result = reader.ReadToEnd();
try { return new JavaScriptSerializer().Deserialize<Config>(result); }
catch { return new Config(); }
}
}
}
示例9: AddUpdateFile
public static void AddUpdateFile(string FileName, string RepoPath)
{
using (var repo = new Repository(RepoPath))
{
repo.Index.Stage(FileName);
}
}
示例10: btnCommit_Click
private void btnCommit_Click(object sender, RibbonControlEventArgs e)
{
//Get Active Project
var pj = Globals.ThisAddIn.Application.ActiveProject;
//Get Project Filename.
var projectFile = pj.FullName;
//Get Directory from File Name
var directory = Path.GetDirectoryName(projectFile);
//Create a new Git Repository
Repository.Init(directory);
//Open the git repository in a using context so its automatically disposed of.
using (var repo = new Repository(directory))
{
// Stage the file
repo.Index.Stage(projectFile);
// Create the committer's signature and commit
var author = new Signature("Richard", "@ARM", DateTime.Now);
var committer = author;
// Commit to the repository
var commit = repo.Commit("Initial commit", author, committer);
}
}
示例11: TestLibGit2_CreateLocalBranches
public void TestLibGit2_CreateLocalBranches()
{
using (var myRepository = new Repository(@"C:\dev1\Gsx.Monitor.Project"))
{
Trace.WriteLine(string.Join("\n", from b in myRepository.Branches select $"{b.FriendlyName}({b.IsRemote})"));
}
}
示例12: RepositoryBase
protected RepositoryBase(string path, string repoName, string userName, string password)
{
Repository = new Repository(path);
RepositoryName = repoName;
UserName = userName;
Password = password;
}
示例13: BuildFileHistory
/// <summary>
/// Builds the file history from a repository path, file path and the reference to object SysVersionControlTmpItem
/// </summary>
/// <param name="repoPath">Repository main path</param>
/// <param name="filePath">File to be pulling the commits</param>
/// <param name="tmpItem">Ref to the SysVersionControlTmpItem object to be inserting to</param>
/// <returns>A SysVersionControlTmpItem filled with the commits</returns>
public static SysVersionControlTmpItem BuildFileHistory(string repoPath, string filePath, ref SysVersionControlTmpItem tmpItem)
{
FileInfo fileInfo = new FileInfo(filePath);
using (var repo = new Repository(repoPath))
{
var indexPath = fileInfo.FullName.Replace(repo.Info.WorkingDirectory, string.Empty);
var commits = repo.Head.Commits.Where(c => c.Parents.Count() == 1 && c.Tree[indexPath] != null && (c.Parents.FirstOrDefault().Tree[indexPath] == null || c.Tree[indexPath].Target.Id != c.Parents.FirstOrDefault().Tree[indexPath].Target.Id));
foreach (Commit commit in commits)
{
tmpItem.User = commit.Author.ToString();
tmpItem.GTXShaShort = commit.Sha.Substring(0, 7);
tmpItem.GTXSha = commit.Sha;
tmpItem.Comment = commit.Message;
tmpItem.ShortComment = commit.MessageShort;
tmpItem.VCSDate = commit.Committer.When.Date;
tmpItem.VCSTime = (int)commit.Committer.When.DateTime.TimeOfDay.TotalSeconds;
tmpItem.Filename_ = FileGetVersion(repoPath, fileInfo.FullName, commit.Sha, Path.Combine(Path.GetTempPath(), string.Format("{0}_{1}", commit.Sha.Substring(0, 7), fileInfo.Name)));
tmpItem.InternalFilename = fileInfo.FullName;
tmpItem.ItemPath = indexPath;
tmpItem.GTXFileRepoStatus = GetFileStatus(repoPath, fileInfo.FullName);
tmpItem.insert();
}
}
return tmpItem;
}
示例14: ChangeBranch
public void ChangeBranch(RepositoryItem repository, string BranchName)
{
var repo = new LibGit2Sharp.Repository(repository.Path);
var branches = repo.Branches.Where(b => b.Name == BranchName).ToList();
if (branches.Any())
{
var localBranch = branches.FirstOrDefault(x => !x.IsRemote);
if (localBranch != null)
{
repo.Checkout(localBranch, new CheckoutOptions(), new Signature(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.Now));
}
else
{
throw new Exception("You must checkout manually the first time");
//COMMENTED THIS OUT AS IT CREATES DUPLICATE REMOTE BRANCHES, For instance R15_Release will duplicate as origin/R15_Release.
//Current work around is to get them to check out the branch manually the first time around.
//var remoteBranch = branches.FirstOrDefault(x => x.IsRemote);
//if (remoteBranch != null)
//{
// var newLocalBranch = repo.CreateBranch(BranchName, remoteBranch.Tip);
// newLocalBranch = repo.Branches.Update(newLocalBranch,
// b =>
// {
// b.TrackedBranch = remoteBranch.CanonicalName;
// });
// repo.Checkout(newLocalBranch, new CheckoutOptions(), new Signature(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.Now));
//}
}
}
}
示例15: NormalizeGitDirectory
public static void NormalizeGitDirectory(string gitDirectory, Arguments arguments, string branch = null)
{
using (var repo = new Repository(gitDirectory))
{
var remote = EnsureOnlyOneRemoteIsDefined(repo);
AddMissingRefSpecs(repo, remote);
Logger.WriteInfo(string.Format("Fetching from remote '{0}' using the following refspecs: {1}.",
remote.Name, string.Join(", ", remote.FetchRefSpecs.Select(r => r.Specification))));
var fetchOptions = BuildFetchOptions(arguments.Username, arguments.Password);
repo.Network.Fetch(remote, fetchOptions);
CreateMissingLocalBranchesFromRemoteTrackingOnes(repo, remote.Name);
if (!repo.Info.IsHeadDetached)
{
Logger.WriteInfo(string.Format("HEAD points at branch '{0}'.", repo.Refs.Head.TargetIdentifier));
return;
}
Logger.WriteInfo(string.Format("HEAD is detached and points at commit '{0}'.", repo.Refs.Head.TargetIdentifier));
if (branch != null)
{
Logger.WriteInfo(string.Format("Checking out local branch 'refs/heads/{0}'.", branch));
repo.Checkout("refs/heads/" + branch);
}
else
{
CreateFakeBranchPointingAtThePullRequestTip(repo);
}
}
}