forked from git-tfs/git-tfs
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git tfs checkout changesetId [-b=branch_name] ex: git-tfs checkout 2365 git-tfs checkout 2365 -b=bugfix_2365 Solve git-tfs#563
- Loading branch information
Showing
6 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.IO; | ||
using NDesk.Options; | ||
using Sep.Git.Tfs.Core; | ||
using StructureMap; | ||
|
||
namespace Sep.Git.Tfs.Commands | ||
{ | ||
[Pluggable("checkout")] | ||
[RequiresValidGitRepository] | ||
[Description("checkout changesetId [-b=branch_name]\n ex: git-tfs checkout 2365\n git-tfs checkout 2365 -b=bugfix_2365\n")] | ||
public class Checkout : GitTfsCommand | ||
{ | ||
private readonly Globals _globals; | ||
private readonly TextWriter _stdout; | ||
|
||
public Checkout(Globals globals, TextWriter stdout) | ||
{ | ||
_globals = globals; | ||
_stdout = stdout; | ||
} | ||
|
||
public OptionSet OptionSet | ||
{ | ||
get | ||
{ | ||
return new OptionSet | ||
{ | ||
{ "b|branch=", "Name of the branch to create", v => BranchName = v }, | ||
}; | ||
} | ||
} | ||
|
||
protected string BranchName { get; set; } | ||
|
||
public int Run(string id) | ||
{ | ||
long changesetId; | ||
if(!long.TryParse(id, out changesetId)) | ||
throw new GitTfsException("error: wrong format for changeset id..."); | ||
var sha = _globals.Repository.FindCommitHashByChangesetId(changesetId); | ||
if (string.IsNullOrEmpty(sha)) | ||
throw new GitTfsException("error: commit not found for this changeset id..."); | ||
string commitishToCheckout = sha; | ||
if (!string.IsNullOrEmpty(BranchName)) | ||
{ | ||
BranchName = _globals.Repository.AssertValidBranchName(BranchName); | ||
if(!_globals.Repository.CreateBranch(BranchName.ToLocalGitRef(), sha)) | ||
throw new GitTfsException("error: can not create branch '" + BranchName + "'"); | ||
_stdout.WriteLine("Branch '" + BranchName + "' created..."); | ||
commitishToCheckout = BranchName; | ||
} | ||
if(!_globals.Repository.Checkout(commitishToCheckout)) | ||
throw new GitTfsException("error: unable to checkout '" + commitishToCheckout + "' due to changes in your workspace!", | ||
new List<string> { "commit or stash your changes before retrying..."}); | ||
return GitTfsExitCodes.OK; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters