From 8e6702c87209e09cc0aeb5d260c164aaecacd71f Mon Sep 17 00:00:00 2001 From: mgill Date: Sat, 10 Aug 2013 16:34:14 -0500 Subject: [PATCH] Get the default checkout ID if not specified on the command line. --- GitTfs/Commands/Unshelve.cs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/GitTfs/Commands/Unshelve.cs b/GitTfs/Commands/Unshelve.cs index 9741f686..ac6677d5 100644 --- a/GitTfs/Commands/Unshelve.cs +++ b/GitTfs/Commands/Unshelve.cs @@ -23,11 +23,11 @@ namespace Sep.Git.Tfs.Commands { _globals = globals; _stdout = stdout; - Branch = _globals.RemoteId; + TfsBranch = null; } public string Owner { get; set; } - public string Branch { get; set; } + public string TfsBranch { get; set; } public OptionSet OptionSet { @@ -37,15 +37,26 @@ namespace Sep.Git.Tfs.Commands { { "u|user=", "Shelveset owner (default: current user)\nUse 'all' to search all shelvesets.", v => Owner = v }, - { "b|branch=", "GIT Branch to apply Shelfset to? (default: TFS default branch)", - v => Branch = v }, + { "b|branch=", "GIT Branch to apply Shelveset to? (default: TFS default branch)", + v => TfsBranch = v }, }; } } public int Run(string shelvesetName, string destinationBranch) { - var remote = _globals.Repository.ReadTfsRemote(Branch); + if (string.IsNullOrEmpty(TfsBranch))//If destination not on command line, set up defaults. + { + TfsBranch = _globals.RemoteId; //Default to main remote id. + //Get the current checkout + TfsChangesetInfo mostRecentUpdate = _globals.Repository.GetLastParentTfsCommits("HEAD").FirstOrDefault(); + if (mostRecentUpdate != null) + { + TfsBranch = mostRecentUpdate.Remote.Id; + } + } + + var remote = _globals.Repository.ReadTfsRemote(TfsBranch); remote.Unshelve(Owner, shelvesetName, destinationBranch); _stdout.WriteLine("Created branch " + destinationBranch + " from shelveset \"" + shelvesetName + "\"."); return GitTfsExitCodes.OK;