Creates a mapping file of ChangesetId-Commit values.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
## Summary
|
||||
|
||||
The exportmap command creates a mapping file of Tfs ChangeSet Id and Commit Id from an already migrated repository.
|
||||
|
||||
## Synopsis
|
||||
|
||||
Usage: git-tfs exportmap [options]
|
||||
where options are:
|
||||
|
||||
-f=VALUE The path to the mapping file
|
||||
-r=VALUE The path to the git repository
|
||||
|
||||
## Examples
|
||||
|
||||
### Create a mapping file from current working directory / git repository
|
||||
|
||||
git tfs exportmap -f mapping.txt -r .
|
||||
@@ -0,0 +1,60 @@
|
||||
using System.ComponentModel;
|
||||
using NDesk.Options;
|
||||
using Newtonsoft.Json;
|
||||
using StructureMap;
|
||||
|
||||
namespace GitTfs.Commands
|
||||
{
|
||||
[Pluggable("exportmap")]
|
||||
[Description("exportmap -f <file> -r <repo>")]
|
||||
public class ExportMap : GitTfsCommand
|
||||
{
|
||||
private readonly Globals _globals;
|
||||
private readonly Init _init;
|
||||
private readonly Help _helper;
|
||||
|
||||
public ExportMap(Globals globals, Init init, Help helper)
|
||||
{
|
||||
_globals = globals;
|
||||
_init = init;
|
||||
_helper = helper;
|
||||
}
|
||||
|
||||
public string FilePath { get; set; }
|
||||
public string RepositoryPath { get; set; }
|
||||
|
||||
public OptionSet OptionSet
|
||||
{
|
||||
get
|
||||
{
|
||||
return new OptionSet
|
||||
{
|
||||
{ "f|file=", "The output file path",
|
||||
f => FilePath = f },
|
||||
{ "r|repository=", "The path to the repository",
|
||||
r => RepositoryPath = r }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public int Run()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(RepositoryPath)
|
||||
|| string.IsNullOrWhiteSpace(FilePath))
|
||||
{
|
||||
return _helper.Run(this);
|
||||
}
|
||||
|
||||
_globals.Repository = _init.GitHelper.MakeRepository(RepositoryPath);
|
||||
var commits = _globals.Repository.GetCommitChangeSetPairs();
|
||||
var dic = JsonConvert.SerializeObject(commits);
|
||||
using (System.IO.StreamWriter file = new System.IO.StreamWriter(FilePath))
|
||||
{
|
||||
file.WriteLine(dic);
|
||||
file.Flush();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -796,5 +796,31 @@ namespace GitTfs.Core
|
||||
|
||||
return sha;
|
||||
}
|
||||
|
||||
public IDictionary<string, string> GetCommitChangeSetPairs()
|
||||
{
|
||||
var allCommits = _repository.Commits.QueryBy(new CommitFilter());
|
||||
var pairs = new Dictionary<string, string>() ;
|
||||
foreach (var c in allCommits)
|
||||
{
|
||||
int changesetId;
|
||||
if (TryParseChangesetId(c.Message, out changesetId))
|
||||
{
|
||||
pairs.Add(changesetId.ToString(), c.Sha);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var note in c.Notes)
|
||||
{
|
||||
if (TryParseChangesetId(note.Message, out changesetId))
|
||||
{
|
||||
pairs.Add(changesetId.ToString(), c.Sha);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pairs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,5 +62,7 @@ namespace GitTfs.Core
|
||||
IEnumerable<GitCommit> FindParentCommits(string fromCommit, string toCommit);
|
||||
bool IsPathIgnored(string relativePath);
|
||||
string CommitGitIgnore(string pathToGitIgnoreFile);
|
||||
|
||||
IDictionary<string, string> GetCommitChangeSetPairs();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
LibGit2Sharp
|
||||
nlog
|
||||
structuremap
|
||||
structuremap
|
||||
Newtonsoft.Json
|
||||
Reference in New Issue
Block a user