本文整理汇总了C#中GitSharp.Core.Repository.UpdateRef方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.UpdateRef方法的具体用法?C# Repository.UpdateRef怎么用?C# Repository.UpdateRef使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GitSharp.Core.Repository
的用法示例。
在下文中一共展示了Repository.UpdateRef方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
protected override void Run ()
{
var cloneDialog = new CloneRepositoryDialog ();
cloneDialog.Run ();
cloneDialog.Destroy ();
var repositoryPath = cloneDialog.RepositoryPath;
URIish source = new URIish (repositoryPath);
var originName = cloneDialog.OriginName;
var destination = cloneDialog.WorkingDirectory;
var workingDirectory = Path.Combine (destination, Constants.DOT_GIT);
if (string.IsNullOrEmpty (originName))
originName = Constants.DEFAULT_REMOTE_NAME;
var rep = new GitSharp.Core.Repository (new DirectoryInfo (workingDirectory));
rep.Create ();
rep.Config.setBoolean ("core", null, "bare", false);
rep.Config.save ();
var rc = new RemoteConfig (rep.Config, originName);
rc.AddURI (source);
rc.AddFetchRefSpec (new RefSpec ().SetForce (true).SetSourceDestination (
Constants.R_HEADS + "*",
Constants.R_REMOTES + originName + "/*"));
rc.Update (rep.Config);
rep.Config.save ();
Transport tn = Transport.open (rep, originName);
FetchResult fetchResult = null;
try
{
fetchResult = tn.fetch (new NullProgressMonitor (), null);
}
catch
{
tn.Dispose ();
}
GitSharp.Core.Ref branch = null;
if (fetchResult != null)
{
var headId = fetchResult.GetAdvertisedRef (Constants.HEAD);
var availableRefs = new List<GitSharp.Core.Ref> ();
foreach (GitSharp.Core.Ref r in fetchResult.AdvertisedRefs)
{
var n = r.Name;
if (!n.StartsWith (Constants.R_HEADS))
continue;
availableRefs.Add (r);
if (headId == null || branch != null)
continue;
if (r.ObjectId.Equals (headId.ObjectId))
branch = r;
}
availableRefs.Sort (RefComparator.INSTANCE);
if (headId != null && branch == null)
branch = headId;
}
if (branch != null)
{
if (!Constants.HEAD.Equals (branch.Name))
{
//rep. (Constants.HEAD, branch.Name);
GitSharp.Core.Commit commit = rep.MapCommit (branch.ObjectId);
RefUpdate update = rep.UpdateRef (Constants.HEAD);
update.NewObjectId = commit.CommitId;
update.forceUpdate ();
var index = new GitIndex (rep);
var tree = commit.TreeEntry;
WorkDirCheckout co = new WorkDirCheckout (rep, rep.WorkingDirectory, index, tree);
co.checkout ();
index.write ();
}
}
else
{
MessageService.ShowError ("Cannot clone: no HEAD advertised by remote.");
}
MessageService.ShowMessage(string.Format("Finished cloning {0} to {1}",
repositoryPath,
destination));
}