public void SwitchToBranch (IProgressMonitor monitor, string branch) { monitor.BeginTask (GettextCatalog.GetString ("Switching to branch {0}", branch), GitService.StashUnstashWhenSwitchingBranches ? 4 : 2); // Get a list of files that are different in the target branch IEnumerable<DiffEntry> statusList = GitUtil.GetChangedFiles (RootRepository, branch); StashCollection stashes = null; Stash stash = null; if (GitService.StashUnstashWhenSwitchingBranches) { stashes = GitUtil.GetStashes (RootRepository); // Remove the stash for this branch, if exists string currentBranch = GetCurrentBranch (); stash = GetStashForBranch (stashes, currentBranch); if (stash != null) stashes.Remove (stash); // Create a new stash for the branch. This allows switching branches // without losing local changes using (var gm = new GitMonitor (monitor)) stash = stashes.Create (gm, GetStashName (currentBranch)); monitor.Step (1); } // Replace with NGit.Api.Git ().Checkout () // Switch to the target branch var checkout = new NGit.Api.Git (RootRepository).Checkout (); checkout.SetName (branch); try { checkout.Call (); } finally { // Restore the branch stash if (GitService.StashUnstashWhenSwitchingBranches) { stash = GetStashForBranch (stashes, branch); if (stash != null) { using (var gm = new GitMonitor (monitor)) stash.Apply (gm); stashes.Remove (stash); } monitor.Step (1); } } // Notify file changes NotifyFileChanges (monitor, statusList); if (BranchSelectionChanged != null) BranchSelectionChanged (this, EventArgs.Empty); monitor.EndTask (); }
public void CreateBranch (string name, string trackSource) { var create = new NGit.Api.Git (RootRepository).BranchCreate (); if (!String.IsNullOrEmpty (trackSource)) create.SetStartPoint (trackSource); create.SetName (name); create.Call (); }
public void AddTag (string name, Revision rev, string message) { var addTag = new NGit.Api.Git (RootRepository).Tag (); var gitRev = (GitRevision)rev; addTag.SetName (name).SetMessage (message).SetObjectId (gitRev.Commit); addTag.SetObjectId (gitRev.Commit).SetTagger (new PersonIdent (RootRepository)); addTag.Call (); }
public void CreateBranchFromCommit (string name, RevCommit id) { var create = new NGit.Api.Git (RootRepository).BranchCreate (); if (id != null) create.SetStartPoint (id); create.SetName (name); create.Call (); }