public void Refresh() { cache.Clear(); if (!string.IsNullOrEmpty(initFolder)) { try { this.repository = Repository.Open(initFolder); if (this.repository != null) { var id = repository.Resolve("HEAD"); var commit = repository.MapCommit(id); this.commitTree = (commit != null ? commit.TreeEntry : new Tree(repository)); this.index = repository.Index; this.index.RereadIfNecessary(); //this.ignoreHandler = new IgnoreHandler(repository); //this.watcher = new FileSystemWatcher(this.repository.WorkingDirectory.FullName); } } catch (Exception ex) { } } }
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)); }