Permalink
Browse files

Refactor unshelve.

  • Loading branch information...
spraints committed Mar 30, 2012
1 parent cc0e392 commit 9f79f1839ac8f37577ef3e371b119508d5bda60d
@@ -185,44 +185,24 @@ public bool HasShelveset(string shelvesetName)
public abstract bool CanShowCheckinDialog { get; }
- [Obsolete("TODO: un-spike-ify this.")]
- public int Unshelve(Unshelve unshelve, IGitTfsRemote remote, IList<string> args)
+ public ITfsChangeset GetShelvesetData(IGitTfsRemote remote, string shelvesetOwner, string shelvesetName)
{
- var shelvesetOwner = unshelve.Owner == "all" ? null : (unshelve.Owner ?? GetAuthenticatedUser());
- if (args.Count != 2)
- {
- _stdout.WriteLine("ERROR: usage: unshelve -u <shelve-owner-name> <shelve-name> <git-branch-name>");
- return GitTfsExitCodes.InvalidArguments;
- }
- var shelvesetName = args[0];
- var destinationBranch = args[1];
-
+ shelvesetOwner = shelvesetOwner == "all" ? null : (shelvesetOwner ?? GetAuthenticatedUser());
var shelvesets = VersionControl.QueryShelvesets(shelvesetName, shelvesetOwner);
if (shelvesets.Length != 1)
{
- _stdout.WriteLine("ERROR: Unable to find shelveset \"" + shelvesetName + "\" (" + shelvesets.Length + " matches). Maybe you've forgot to set owner name?");
- WriteShelvesetsToStdout(shelvesets);
- return GitTfsExitCodes.InvalidArguments;
+ throw new GitTfsException("Unable to find " + shelvesetOwner + "'s shelveset \"" + shelvesetName + "\" (" + shelvesets.Length + " matches).")
+ .WithRecommendation("Try providing the shelveset owner.");
}
var shelveset = shelvesets.First();
- var destinationRef = "refs/heads/" + destinationBranch;
- if (File.Exists(Path.Combine(remote.Repository.GitDir, destinationRef)))
- {
- _stdout.WriteLine("ERROR: Destination branch (" + destinationBranch + ") already exists!");
- return GitTfsExitCodes.ForceRequired;
- }
-
var change = VersionControl.QueryShelvedChanges(shelveset).Single();
- var gremote = (GitTfsRemote) remote;
var wrapperForVersionControlServer =
_bridge.Wrap<WrapperForVersionControlServer, VersionControlServer>(VersionControl);
+ // TODO - containerify this (no `new`)!
var fakeChangeset = new FakeChangeset(shelveset, change, wrapperForVersionControlServer, _bridge);
- var tfsChangeset = new TfsChangeset(remote.Tfs, fakeChangeset, _stdout)
- {Summary = new TfsChangesetInfo {Remote = remote}};
- gremote.Apply(tfsChangeset, destinationRef);
- _stdout.WriteLine("Created branch " + destinationBranch + " from shelveset \"" + shelvesetName + "\".");
- return GitTfsExitCodes.OK;
+ var tfsChangeset = new TfsChangeset(remote.Tfs, fakeChangeset, _stdout) { Summary = new TfsChangesetInfo { Remote = remote } };
+ return tfsChangeset;
}
public int ListShelvesets(ShelveList shelveList, IGitTfsRemote remote)
@@ -70,7 +70,7 @@ public bool HasShelveset(string shelvesetName)
throw new NotImplementedException();
}
- public int Unshelve(Unshelve unshelve, IGitTfsRemote remote, IList<string> args)
+ public ITfsChangeset GetShelvesetData(IGitTfsRemote remote, string shelvesetOwner, string shelvesetName)
{
throw new NotImplementedException();
}
@@ -12,15 +12,17 @@
namespace Sep.Git.Tfs.Commands
{
[Pluggable("unshelve")]
- [Description("unshelve -u <shelve-owner-name> <shelve-name> <git-branch-name>")]
+ [Description("unshelve -u <shelve-owner-name> <shelve-name> <destination-branch>")]
[RequiresValidGitRepository]
public class Unshelve : GitTfsCommand
{
private readonly Globals _globals;
+ private readonly TextWriter _stdout;
- public Unshelve(Globals globals)
+ public Unshelve(Globals globals, TextWriter stdout)
{
_globals = globals;
+ _stdout = stdout;
}
public string Owner { get; set; }
@@ -37,10 +39,12 @@ public OptionSet OptionSet
}
}
- public int Run(IList<string> args)
+ public int Run(string shelvesetName, string destinationBranch)
{
var remote = _globals.Repository.ReadTfsRemote(_globals.RemoteId);
- return remote.Tfs.Unshelve(this, remote, args);
+ remote.Unshelve(Owner, shelvesetName, destinationBranch);
+ _stdout.WriteLine("Created branch " + destinationBranch + " from shelveset \"" + shelvesetName + "\".");
+ return GitTfsExitCodes.OK;
}
}
}
@@ -171,6 +171,11 @@ public void QuickFetch(int changesetId)
throw new NotImplementedException();
}
+ public void Unshelve(string a, string b, string c)
+ {
+ throw new NotImplementedException();
+ }
+
public void Shelve(string shelvesetName, string treeish, TfsChangesetInfo parentChangeset, bool evaluateCheckinPolicies)
{
throw new NotImplementedException();
@@ -422,6 +422,15 @@ private void PushEnvironment(IDictionary<string, string> desiredEnvironment, IDi
}
}
+ public void Unshelve(string shelvesetOwner, string shelvesetName, string destinationBranch)
+ {
+ var destinationRef = "refs/heads/" + destinationBranch;
+ if (File.Exists(Path.Combine(Repository.GitDir, destinationRef)))
+ throw new GitTfsException("ERROR: Destination branch (" + destinationBranch + ") already exists!");
+ var shelvesetChangeset = Tfs.GetShelvesetData(this, shelvesetOwner, shelvesetName);
+ Apply(shelvesetChangeset, destinationRef);
+ }
+
public void Shelve(string shelvesetName, string head, TfsChangesetInfo parentChangeset, bool evaluateCheckinPolicies)
{
Tfs.WithWorkspace(WorkingDirectory, this, parentChangeset,
@@ -26,6 +26,7 @@ public interface IGitTfsRemote
void FetchWithMerge(long mergeChangesetId, params string[] parentCommitsHashes);
void QuickFetch();
void QuickFetch(int changesetId);
+ void Unshelve(string shelvesetOwner, string shelvesetName, string destinationBranch);
void Shelve(string shelvesetName, string treeish, TfsChangesetInfo parentChangeset, bool evaluateCheckinPolicies);
bool HasShelveset(string shelvesetName);
long CheckinTool(string head, TfsChangesetInfo parentChangeset);
@@ -22,7 +22,7 @@ public interface ITfsHelper
IChangeset GetChangeset(int changesetId);
bool MatchesUrl(string tfsUrl);
bool HasShelveset(string shelvesetName);
- int Unshelve(Unshelve unshelve, IGitTfsRemote remote, IList<string> args);
+ ITfsChangeset GetShelvesetData(IGitTfsRemote remote, string shelvesetOwner, string shelvesetName);
int ListShelvesets(ShelveList shelveList, IGitTfsRemote remote);
bool CanShowCheckinDialog { get; }
long ShowCheckinDialog(IWorkspace workspace, IPendingChange[] pendingChanges, IEnumerable<IWorkItemCheckedInfo> checkedInfos, string checkinComment);

0 comments on commit 9f79f18

Please sign in to comment.