本文整理汇总了C#中LibGit2Sharp.Repository.Checkout方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.Checkout方法的具体用法?C# Repository.Checkout怎么用?C# Repository.Checkout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LibGit2Sharp.Repository
的用法示例。
在下文中一共展示了Repository.Checkout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateSpecificVersion
public void GenerateSpecificVersion(RepositoryUrl repositoryUrl, string commit)
{
var pathResolver = new PathResolver(repositoryUrl.Url, commit);
var repositoryFolder = pathResolver.GetRepositoryPath();
var repository = new Repository(repositoryFolder + "/.git");
repository.Checkout(commit);
var commitFolder = pathResolver.GetVersionPath();
Directory.CreateDirectory(commitFolder);
DirectoryCopy(repositoryFolder, commitFolder, true);
repository.Checkout(repository.Branches["master"]);
}
示例2: 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);
}
}
}
示例3: Checkout
public Branch Checkout(string branch)
{
using (var repo = new Repository(_settings.Workspace))
{
return repo.Checkout(branch);
}
}
示例4: 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));
//}
}
}
}
示例5: GivenARemoteGitRepositoryWithCommitsAndBranches_ThenClonedLocalShouldMatchRemoteVersion
public void GivenARemoteGitRepositoryWithCommitsAndBranches_ThenClonedLocalShouldMatchRemoteVersion()
{
using (var fixture = new RemoteRepositoryFixture(
path =>
{
Repository.Init(path);
Console.WriteLine("Created git repository at '{0}'", path);
var repo = new Repository(path);
repo.MakeCommits(5);
repo.CreateBranch("develop");
repo.CreateBranch("release-1.0");
repo.Checkout("release-1.0");
repo.MakeCommits(5);
return repo;
},
new Config()))
{
fixture.AssertFullSemver("1.0.0-beta.1+5");
fixture.AssertFullSemver("1.0.0-beta.1+5", fixture.LocalRepository);
}
}
示例6: GivenARemoteGitRepositoryWithCommitsAndBranches_ThenClonedLocalShouldMatchRemoteVersion
public void GivenARemoteGitRepositoryWithCommitsAndBranches_ThenClonedLocalShouldMatchRemoteVersion()
{
using (var fixture = new RemoteRepositoryFixture(
path =>
{
Repository.Init(path);
Console.WriteLine("Created git repository at '{0}'", path);
var repo = new Repository(path);
repo.MakeCommits(5);
repo.CreateBranch("develop");
repo.CreateBranch("release-1.0");
repo.Checkout("release-1.0");
repo.MakeCommits(5);
return repo;
}))
{
GitRepositoryHelper.NormalizeGitDirectory(fixture.LocalRepositoryFixture.RepositoryPath, new AuthenticationInfo(), noFetch: false, currentBranch: string.Empty);
fixture.AssertFullSemver("1.0.0-beta.1+5");
fixture.AssertFullSemver("1.0.0-beta.1+5", fixture.LocalRepositoryFixture.Repository);
}
}
示例7: CheckOut
public void CheckOut( string branchName )
{
using( var r = new Repository( Path ) )
{
Branch b = r.Branches[branchName];
r.Checkout( b, new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force } );
}
}
示例8: Main
public static void Main(string[] args)
{
try
{
log("started...");
var repoUrl = args[0];
var branchName = "master";
var username = args[1];
var password = "";
if (args.Length == 3)
{
password = args[2];
}
var pathSplit = repoUrl.Split('/');
var repoName = pathSplit.Last();
var author = new Signature("scarletapi", "@gmail", DateTime.Now);
var repoDir = new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), repoName));
var repoPath = repoDir.FullName;
if (String.IsNullOrEmpty(username))
{
throw new Exception("Must have username");
}
if (String.IsNullOrEmpty(password))
{
repoUrl = repoUrl.Replace(pathSplit[2], String.Format("{0}@{2}", username, password, pathSplit[2]));
}
else
{
repoUrl = repoUrl.Replace(pathSplit[2], String.Format("{0}:{1}@{2}", username, password, pathSplit[2]));
}
log("checking if repo exists");
if (!repoDir.Exists || !Repository.IsValid(repoPath))
{
if (repoDir.Exists)
{
repoDir.Delete(true);
}
var cloneOptions = new CloneOptions();
cloneOptions.BranchName = branchName;
log("cloning {0} repository at url {1}", repoName, repoUrl);
repoUrl = Repository.Clone(repoUrl, repoPath, cloneOptions);
using (var repo = new LibGit2Sharp.Repository(repoPath))
{
repo.Checkout(repo.Branches[branchName], new CheckoutOptions());
}
}
}
catch (Exception e)
{
log("ERROR: {0}", e.Message);
}
}
示例9: using
public void GivenARemoteWithATagOnMaster_AndAPullRequestWithTwoCommits_AndBuildIsRunningInTeamCity_VersionIsCalculatedProperly(string pullRequestRef)
{
using (var fixture = new EmptyRepositoryFixture())
{
var remoteRepositoryPath = PathHelper.GetTempPath();
Repository.Init(remoteRepositoryPath);
using (var remoteRepository = new Repository(remoteRepositoryPath))
{
remoteRepository.Config.Set("user.name", "Test");
remoteRepository.Config.Set("user.email", "[email protected]");
fixture.Repository.Network.Remotes.Add("origin", remoteRepositoryPath);
Console.WriteLine("Created git repository at {0}", remoteRepositoryPath);
remoteRepository.MakeATaggedCommit("1.0.3");
var branch = remoteRepository.CreateBranch("FeatureBranch");
remoteRepository.Checkout(branch);
remoteRepository.MakeCommits(2);
remoteRepository.Checkout(remoteRepository.Head.Tip.Sha);
//Emulate merge commit
var mergeCommitSha = remoteRepository.MakeACommit().Sha;
remoteRepository.Checkout("master"); // HEAD cannot be pointing at the merge commit
remoteRepository.Refs.Add(pullRequestRef, new ObjectId(mergeCommitSha));
// Checkout PR commit
Commands.Fetch((Repository)fixture.Repository, "origin", new string[0], new FetchOptions(), null);
fixture.Repository.Checkout(mergeCommitSha);
}
var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, isTeamCity: true);
result.ExitCode.ShouldBe(0);
result.OutputVariables.FullSemVer.ShouldBe("1.0.4-PullRequest0005.3");
// Cleanup repository files
DirectoryHelper.DeleteDirectory(remoteRepositoryPath);
}
}
示例10: NServiceBusDevelopOlderCommit
public void NServiceBusDevelopOlderCommit()
{
using (var repository = new Repository(@"C:\Code\NServiceBus"))
{
var branch = repository.Branches.First(x => x.Name == "develop");
repository.Checkout("c0e0a5e13775552cd3e08e039f453e4cf1fd4235");
var finder = new GitVersionFinder();
var version = finder.FindVersion(new GitVersionContext(repository, branch, new Config()));
Debug.WriteLine(version.Major);
Debug.WriteLine(version.Minor);
Debug.WriteLine(version.Patch);
Debug.WriteLine(version.PreReleaseTag);
Debug.WriteLine(version.BuildMetaData);
}
}
示例11: RepositoryWrapper
public RepositoryWrapper(Repository repo)
{
this.repo = repo;
Head = async (i) => { return new BranchWrapper(repo, repo.Head); };
Config = async (i) => { return repo.Config; };
Index = async (i) => { return repo.Index; };
Ignore = async (i) => { return repo.Ignore; };
Network = async (i) => { return new NetworkWrapper(repo.Network); };
ObjectDatabase = async (i) => { return repo.ObjectDatabase; };
Refs = async (i) => { return repo.Refs; };
Commits = async (i) => { return repo.Commits.Select(c => new CommitWrapper(c)); };
Tags = async (i) => { return repo.Tags; };
Stashes = async (i) => { return repo.Stashes; };
Info = async (i) => { return repo.Info; };
Diff = async (i) => { return repo.Diff; };
Notes = async (i) => { return repo.Notes; };
Submodules = async (i) => { return repo.Submodules; };
Dispose = async (i) => { repo.Dispose(); return null; };
Lookup = async (id) => {
var found = repo.Lookup(id.ToString());
if (found.GetType() == typeof(Commit)) {
return new CommitWrapper((Commit)found);
} else {
return found;
}
};
Branches = async (i) => repo.Branches.Select(b => new BranchWrapper(repo, b)).ToDictionary(b => b.Name);
Reset = async (dynamic i) => {
var modeName = ((string)i.mode).ToLower();
ResetMode mode;
if (modeName == "soft") {
mode = ResetMode.Soft;
} else if (modeName == "mixed") {
mode = ResetMode.Mixed;
} else {
mode = ResetMode.Hard;
}
var committish = (string)i.committish;
repo.Reset(mode, committish, null, null);
return null;
};
Checkout = async (i) => {
var branch = repo.Branches.First(b => b.Name == i.ToString());
repo.Checkout(branch);
return branch;
};
}
示例12: CreateFakeBranchPointingAtThePullRequestTip
private static void CreateFakeBranchPointingAtThePullRequestTip(Repository repo)
{
var remote = repo.Network.Remotes.Single();
var remoteTips = repo.Network.ListReferences(remote);
var headTipSha = repo.Head.Tip.Sha;
var refs = remoteTips.Where(r => r.TargetIdentifier == headTipSha).ToList();
if (refs.Count == 0)
{
Log.ErrorAndThrowException<GitLinkException>("Couldn't find any remote tips from remote '{0}' pointing at the commit '{1}'.", remote.Url, headTipSha);
}
if (refs.Count > 1)
{
var names = string.Join(", ", refs.Select(r => r.CanonicalName));
Log.ErrorAndThrowException<GitLinkException>("Found more than one remote tip from remote '{0}' pointing at the commit '{1}'. Unable to determine which one to use ({2}).", remote.Url, headTipSha, names);
}
var canonicalName = refs[0].CanonicalName;
Log.Info("Found remote tip '{0}' pointing at the commit '{1}'.", canonicalName, headTipSha);
if (!canonicalName.StartsWith("refs/pull/"))
{
Log.ErrorAndThrowException<Exception>("Remote tip '{0}' from remote '{1}' doesn't look like a valid pull request.", canonicalName, remote.Url);
}
var fakeBranchName = canonicalName.Replace("refs/pull/", "refs/heads/pull/");
Log.Info("Creating fake local branch '{0}'.", fakeBranchName);
repo.Refs.Add(fakeBranchName, new ObjectId(headTipSha));
Log.Info("Checking local branch '{0}' out.", fakeBranchName);
repo.Checkout(fakeBranchName);
}
示例13: Main
static void Main(string[] args)
{
string repopath = @"C:\users\rasquill\documents\github\azure-docs-pr\";
List<TOC> TOCs = new List<TOC>();
using (Repository repo = new Repository(repopath))
{
repo.Checkout("master");
//Console.WriteLine(repo.Index.Count());
var tocfiles = (from f in repo.Index
where
f.Path.Contains("TOC.md")
&& f.Path.Contains(@"articles\")
select f.Path);
foreach (var tocfile in tocfiles)
{
//Console.WriteLine(File.ReadAllText(repo.Info.WorkingDirectory + tocfile));
TOCs.Add(new TOC(repo.Info.WorkingDirectory + tocfile));
}
}
Console.ReadLine();
}
示例14: FetchGitSourceLocally
protected void FetchGitSourceLocally(TemplateSource source, string destFolder) {
if (source == null) { throw new ArgumentNullException("source"); }
if (string.IsNullOrEmpty(destFolder)) { throw new ArgumentNullException("destFolder"); }
// TODO: these methods should be renamed since fetch means something in git
try {
var destDirInfo = new DirectoryInfo(destFolder);
if (destDirInfo.Exists) {
ResetDirectoryAttributes(destDirInfo);
// TODO: if the folder exists and there is a .git folder then we should do a fetch/merge or pull
destDirInfo.Delete(true);
}
// clone it
var repoPath = Repository.Clone(source.Location.AbsoluteUri, destFolder);
var repo = new Repository(repoPath);
Branch branch = repo.Checkout(source.Branch);
branch.Checkout();
}
catch (Exception ex) {
UpdateStatusBar("There was an error check the activity log");
// TODO: we should log this error
string msg = ex.ToString();
System.Windows.Forms.MessageBox.Show(msg);
}
}
示例15: StandardExecutionMode_CannotDetermineTheVersionFromADetachedHead
public void StandardExecutionMode_CannotDetermineTheVersionFromADetachedHead()
{
var repoPath = Clone(ASBMTestRepoWorkingDirPath);
using (var repo = new Repository(repoPath))
{
repo.Checkout("469f851");
Assert.IsTrue(repo.Info.IsHeadDetached);
}
var task = new UpdateAssemblyInfo
{
BuildEngine = new MockBuildEngine(),
SolutionDirectory = repoPath,
};
var exception = Assert.Throws<ErrorException>(task.InnerExecute);
Assert.AreEqual("It looks like the branch being examined is a detached Head pointing to commit '469f851'. Without a proper branch name GitVersion cannot determine the build version.", exception.Message);
}