diff --git a/GitTfs.Vs2010/TfsHelper.Vs2010.cs b/GitTfs.Vs2010/TfsHelper.Vs2010.cs index e29441f32..7f821fc91 100644 --- a/GitTfs.Vs2010/TfsHelper.Vs2010.cs +++ b/GitTfs.Vs2010/TfsHelper.Vs2010.cs @@ -10,7 +10,7 @@ namespace Sep.Git.Tfs.Vs2010 { public class TfsHelper : TfsHelperBase { - public TfsHelper(TextWriter stdout, TfsApiBridge bridge, IContainer container) : base(stdout, bridge, container) + public TfsHelper(TfsApiBridge bridge, IContainer container) : base(bridge, container) { } diff --git a/GitTfs.Vs2012/TfsHelper.Vs2012.cs b/GitTfs.Vs2012/TfsHelper.Vs2012.cs index b50377352..beb833a59 100644 --- a/GitTfs.Vs2012/TfsHelper.Vs2012.cs +++ b/GitTfs.Vs2012/TfsHelper.Vs2012.cs @@ -8,7 +8,7 @@ public class TfsHelper : TfsHelperVs2012Base { protected override string TfsVersionString { get { return "11.0"; } } - public TfsHelper(TextWriter stdout, TfsApiBridge bridge, IContainer container) - : base(stdout, bridge, container) { } + public TfsHelper(TfsApiBridge bridge, IContainer container) + : base(bridge, container) { } } } diff --git a/GitTfs.Vs2013/TfsHelper.Vs2013.cs b/GitTfs.Vs2013/TfsHelper.Vs2013.cs index 58bb3985f..7db87431f 100644 --- a/GitTfs.Vs2013/TfsHelper.Vs2013.cs +++ b/GitTfs.Vs2013/TfsHelper.Vs2013.cs @@ -8,7 +8,7 @@ public class TfsHelper : TfsHelperVs2012Base { protected override string TfsVersionString { get { return "12.0"; } } - public TfsHelper(TextWriter stdout, TfsApiBridge bridge, IContainer container) - : base(stdout, bridge, container) { } + public TfsHelper(TfsApiBridge bridge, IContainer container) + : base(bridge, container) { } } } diff --git a/GitTfs.Vs2015/TfsHelper.Vs2015.cs b/GitTfs.Vs2015/TfsHelper.Vs2015.cs index a7b31940e..593cec684 100644 --- a/GitTfs.Vs2015/TfsHelper.Vs2015.cs +++ b/GitTfs.Vs2015/TfsHelper.Vs2015.cs @@ -8,8 +8,8 @@ public class TfsHelper : TfsHelperVs2012Base { protected override string TfsVersionString { get { return "14.0"; } } - public TfsHelper(TextWriter stdout, TfsApiBridge bridge, IContainer container) - : base(stdout, bridge, container) { } + public TfsHelper(TfsApiBridge bridge, IContainer container) + : base(bridge, container) { } protected override string GetDialogAssemblyPath() { diff --git a/GitTfs.VsCommon/TfsHelper.Common.cs b/GitTfs.VsCommon/TfsHelper.Common.cs index 3e1ea3e04..dbb327642 100644 --- a/GitTfs.VsCommon/TfsHelper.Common.cs +++ b/GitTfs.VsCommon/TfsHelper.Common.cs @@ -25,15 +25,13 @@ namespace Sep.Git.Tfs.VsCommon { public abstract class TfsHelperBase : ITfsHelper { - protected readonly TextWriter _stdout; protected readonly TfsApiBridge _bridge; private readonly IContainer _container; protected TfsTeamProjectCollection _server; private static bool _resolverInstalled; - public TfsHelperBase(TextWriter stdout, TfsApiBridge bridge, IContainer container) + public TfsHelperBase(TfsApiBridge bridge, IContainer container) { - _stdout = stdout; _bridge = bridge; _container = container; if (!_resolverInstalled) @@ -139,12 +137,12 @@ private void NonFatalError(object sender, ExceptionEventArgs e) { if (e.Failure != null) { - _stdout.WriteLine(e.Failure.Message); + Trace.TraceInformation(e.Failure.Message); Trace.WriteLine("Failure: " + e.Failure.Inspect(), "tfs non-fatal error"); } if (e.Exception != null) { - _stdout.WriteLine(e.Exception.Message); + Trace.TraceInformation(e.Exception.Message); Trace.WriteLine("Exception: " + e.Exception.Inspect(), "tfs non-fatal error"); } } @@ -312,9 +310,11 @@ private void GetRootChangesetForBranch(IList rootBranches, string tf GetRelevantChangesetBasedOnChangeType(mergedItemsToFirstChangesetInBranchToCreate, tfsPathParentBranch, tfsPathBranchToCreate, out renameFromBranch); AddNewRootBranch(rootBranches, new RootBranch(rootChangesetInParentBranch, tfsPathBranchToCreate)); - Trace.WriteLineIf(renameFromBranch != null, "Found original branch '" + renameFromBranch + "' (renamed in branch '" + tfsPathBranchToCreate + "')"); if (renameFromBranch != null) + { + Trace.WriteLine("Found original branch '" + renameFromBranch + "' (renamed in branch '" + tfsPathBranchToCreate + "')"); GetRootChangesetForBranch(rootBranches, renameFromBranch); + } } catch (VersionControlException) { @@ -428,7 +428,7 @@ private int GetRelevantChangesetBasedOnChangeType(IEnumerable merges, } if (merge == null) { - _stdout.WriteLine("warning: git-tfs was unable to find the root changeset (ie the last common commit) between the branch '" + Trace.TraceWarning("warning: git-tfs was unable to find the root changeset (ie the last common commit) between the branch '" + tfsPathBranchToCreate + "' and its parent branch '" + tfsPathParentBranch + "'.\n" + "(Any help to add support of this special case is welcomed! Open an issue on https://github.com/git-tfs/git-tfs/issues )\n\n" + "To be able to continue to fetch the changesets from Tfs,\nplease enter the root changeset id between the branch '" @@ -490,7 +490,7 @@ private int AskForRootChangesetId() int changesetId; while (true) { - _stdout.Write("Please specify the root changeset id (or 'exit' to stop the process):"); + Trace.TraceInformation("Please specify the root changeset id (or 'exit' to stop the process):"); var read = Console.ReadLine(); if (read == "exit") throw new GitTfsException("Exiting...(fetching stopped by user!)"); @@ -548,7 +548,7 @@ private IEnumerable GetMergeInfo(string tfsPathBranchToCreate, string TargetChangeType = extendedMerge.TargetItem != null ? extendedMerge.TargetItem.ChangeType : 0 }; mergedItemsToFirstChangesetInBranchToCreate.Add(lastMerge); - Trace.WriteLine(lastMerge, "Merge"); + Trace.WriteLine("Merge: " + lastMerge); } return mergedItemsToFirstChangesetInBranchToCreate; } @@ -737,7 +737,7 @@ public void CleanupWorkspaces(string workingDirectory) { // Normally, the workspace will have one mapping, mapped to the git-tfs // workspace folder. In that case, we just delete the workspace. - _stdout.WriteLine("Removing workspace \"" + workspace.DisplayName + "\"."); + Trace.TraceInformation("Removing workspace \"" + workspace.DisplayName + "\"."); workspace.Delete(); } else @@ -749,7 +749,7 @@ public void CleanupWorkspaces(string workingDirectory) var fullWorkingDirectoryPath = Path.GetFullPath(workingDirectory); foreach (var mapping in workspace.Folders.Where(f => fullWorkingDirectoryPath.StartsWith(Path.GetFullPath(f.LocalItem), StringComparison.CurrentCultureIgnoreCase))) { - _stdout.WriteLine("Removing @\"" + mapping.LocalItem + "\" from workspace \"" + workspace.DisplayName + "\"."); + Trace.TraceInformation("Removing @\"" + mapping.LocalItem + "\" from workspace \"" + workspace.DisplayName + "\"."); workspace.DeleteMapping(mapping); } } @@ -764,7 +764,7 @@ public void CleanupWorkspaces(string workingDirectory) /// TFS randomly seems to report a workspace removed/deleted BUT subsequent calls by Git-TFS suggest that the delete hasn't actually been completed. /// This suggest that deletes may be queued and take a lower priority than other actions, especially if the TFS server is under load. /// - private static void TryToDeleteWorkspace(Workspace workspace) + private void TryToDeleteWorkspace(Workspace workspace) { // Try and ensure the client and TFS Server are synchronized. workspace.Refresh(); @@ -812,7 +812,7 @@ public ITfsChangeset GetShelvesetData(IGitTfsRemote remote, string shelvesetOwne _bridge.Wrap(VersionControl); // TODO - containerify this (no `new`)! var fakeChangeset = new Unshelveable(shelveset, change, wrapperForVersionControlServer, _bridge); - var tfsChangeset = new TfsChangeset(remote.Tfs, fakeChangeset, _stdout, null) { Summary = new TfsChangesetInfo { Remote = remote } }; + var tfsChangeset = new TfsChangeset(remote.Tfs, fakeChangeset, null) { Summary = new TfsChangesetInfo { Remote = remote } }; return tfsChangeset; } @@ -826,12 +826,12 @@ public int ListShelvesets(ShelveList shelveList, IGitTfsRemote remote) } catch (IdentityNotFoundException) { - _stdout.WriteLine("User '{0}' not found", shelveList.Owner); + Trace.TraceInformation("User '{0}' not found", shelveList.Owner); return GitTfsExitCodes.InvalidArguments; } if (shelvesets.Empty()) { - _stdout.WriteLine("No changesets found."); + Trace.TraceInformation("No changesets found."); return GitTfsExitCodes.OK; } @@ -853,7 +853,7 @@ public int ListShelvesets(ShelveList shelveList, IGitTfsRemote remote) shelvesets = shelvesets.OrderBy(s => s.Comment); break; default: - _stdout.WriteLine("ERROR: sorting criteria '{0}' is invalid. Possible values are: date, owner, name, comment", sortBy); + Trace.TraceInformation("ERROR: sorting criteria '{0}' is invalid. Possible values are: date, owner, name, comment", sortBy); return GitTfsExitCodes.InvalidArguments; } } @@ -871,7 +871,7 @@ private void WriteShelvesetsToStdout(IEnumerable shelvesets) { foreach (var shelveset in shelvesets) { - _stdout.WriteLine("{0,-22} {1,-20}", shelveset.OwnerName, shelveset.Name); + Trace.TraceInformation("{0,-22} {1,-20}", shelveset.OwnerName, shelveset.Name); } } @@ -879,11 +879,11 @@ private void WriteShelvesetsToStdoutDetailed(IEnumerable shelvesets) { foreach (var shelveset in shelvesets) { - _stdout.WriteLine("Name : {0}", shelveset.Name); - _stdout.WriteLine("Owner : {0}", shelveset.OwnerName); - _stdout.WriteLine("Date : {0:g}", shelveset.CreationDate); - _stdout.WriteLine("Comment: {0}", shelveset.Comment); - _stdout.WriteLine(); + Trace.TraceInformation("Name : {0}", shelveset.Name); + Trace.TraceInformation("Owner : {0}", shelveset.OwnerName); + Trace.TraceInformation("Date : {0:g}", shelveset.CreationDate); + Trace.TraceInformation("Comment: {0}", shelveset.Comment); + Trace.TraceInformation(string.Empty); } } @@ -1364,22 +1364,22 @@ public int QueueGatedCheckinBuild(Uri buildDefinitionUri, string buildDefinition buildRequest.Reason = BuildReason.CheckInShelveset; buildRequest.GatedCheckInTicket = checkInTicket; - _stdout.WriteLine("Launching build '" + buildDefinitionName + "' to validate your shelveset..."); + Trace.TraceInformation("Launching build '" + buildDefinitionName + "' to validate your shelveset..."); var queuedBuild = buildServer.QueueBuild(buildRequest); - _stdout.WriteLine("Waiting for gated check-in build result..."); + Trace.TraceInformation("Waiting for gated check-in build result..."); do { - _stdout.Write("."); + Console.Write("."); System.Threading.Thread.Sleep(5000); queuedBuild.Refresh(QueryOptions.Definitions); } while (queuedBuild.Build == null || !queuedBuild.Build.BuildFinished); - _stdout.WriteLine(string.Empty); + Trace.TraceInformation(string.Empty); var build = GetSpecificBuildFromQueuedBuild(queuedBuild, shelvesetName); if (build.Status == BuildStatus.Succeeded) { - _stdout.WriteLine("Build was successful! Your changes have been checked in."); + Trace.TraceInformation("Build was successful! Your changes have been checked in."); return VersionControl.GetLatestChangesetId(); } else diff --git a/GitTfs.VsCommon/TfsHelper.Vs2012Base.cs b/GitTfs.VsCommon/TfsHelper.Vs2012Base.cs index 2657735f2..d70f02822 100644 --- a/GitTfs.VsCommon/TfsHelper.Vs2012Base.cs +++ b/GitTfs.VsCommon/TfsHelper.Vs2012Base.cs @@ -15,8 +15,8 @@ namespace Sep.Git.Tfs.VsCommon public abstract class TfsHelperVs2012Base : TfsHelperBase { protected abstract string TfsVersionString { get; } - protected TfsHelperVs2012Base(TextWriter stdout, TfsApiBridge bridge, IContainer container) - : base(stdout, bridge, container) { } + protected TfsHelperVs2012Base(TfsApiBridge bridge, IContainer container) + : base(bridge, container) { } protected override bool HasWorkItems(Changeset changeset) { diff --git a/GitTfs.VsFake/TfsHelper.VsFake.cs b/GitTfs.VsFake/TfsHelper.VsFake.cs index 9ab6b7262..cab2f2498 100644 --- a/GitTfs.VsFake/TfsHelper.VsFake.cs +++ b/GitTfs.VsFake/TfsHelper.VsFake.cs @@ -25,14 +25,12 @@ public class TfsHelper : ITfsHelper #region misc/null IContainer _container; - TextWriter _stdout; Script _script; FakeVersionControlServer _versionControlServer; - public TfsHelper(IContainer container, TextWriter stdout, Script script) + public TfsHelper(IContainer container, Script script) { _container = container; - _stdout = stdout; _script = script; _versionControlServer = new FakeVersionControlServer(_script); } diff --git a/GitTfs/Commands/Bootstrap.cs b/GitTfs/Commands/Bootstrap.cs index f29f989bd..38db17b38 100644 --- a/GitTfs/Commands/Bootstrap.cs +++ b/GitTfs/Commands/Bootstrap.cs @@ -3,6 +3,7 @@ using NDesk.Options; using Sep.Git.Tfs.Core; using StructureMap; +using System.Diagnostics; namespace Sep.Git.Tfs.Commands { @@ -14,14 +15,12 @@ public class Bootstrap : GitTfsCommand { private readonly RemoteOptions _remoteOptions; private readonly Globals _globals; - private readonly TextWriter _stdout; private readonly Bootstrapper _bootstrapper; - public Bootstrap(RemoteOptions remoteOptions, Globals globals, TextWriter stdout, Bootstrapper bootstrapper) + public Bootstrap(RemoteOptions remoteOptions, Globals globals, Bootstrapper bootstrapper) { _remoteOptions = remoteOptions; _globals = globals; - _stdout = stdout; _bootstrapper = bootstrapper; } @@ -41,13 +40,13 @@ public int Run(string commitish) foreach (var parent in tfsParents) { GitCommit commit = _globals.Repository.GetCommit(parent.GitCommit); - _stdout.WriteLine("commit {0}\nAuthor: {1} <{2}>\nDate: {3}\n\n {4}", + Trace.TraceInformation("commit {0}\nAuthor: {1} <{2}>\nDate: {3}\n\n {4}", commit.Sha, commit.AuthorAndEmail.Item1, commit.AuthorAndEmail.Item2, commit.When.ToString("ddd MMM d HH:mm:ss zzz"), commit.Message.Replace("\n","\n ").TrimEnd(' ')); _bootstrapper.CreateRemote(parent); - _stdout.WriteLine(); + Trace.TraceInformation(string.Empty); } return GitTfsExitCodes.OK; } diff --git a/GitTfs/Commands/Branch.cs b/GitTfs/Commands/Branch.cs index 929d88c5c..07e823501 100644 --- a/GitTfs/Commands/Branch.cs +++ b/GitTfs/Commands/Branch.cs @@ -23,7 +23,6 @@ namespace Sep.Git.Tfs.Commands public class Branch : GitTfsCommand { private Globals globals; - private TextWriter stdout; private readonly Help helper; private readonly Cleanup cleanup; private readonly InitBranch initBranch; @@ -63,10 +62,9 @@ public OptionSet OptionSet } } - public Branch(Globals globals, TextWriter stdout, Help helper, Cleanup cleanup, InitBranch initBranch, Rcheckin rcheckin) + public Branch(Globals globals, Help helper, Cleanup cleanup, InitBranch initBranch, Rcheckin rcheckin) { this.globals = globals; - this.stdout = stdout; this.helper = helper; this.cleanup = cleanup; this.initBranch = initBranch; @@ -95,7 +93,7 @@ public int Run() if (!IsCommandWellUsed()) return helper.Run(this); - globals.WarnOnGitVersion(stdout); + globals.WarnOnGitVersion(); VerifyCloneAllRepository(); @@ -118,7 +116,7 @@ public int Run(string param) VerifyCloneAllRepository(); - globals.WarnOnGitVersion(stdout); + globals.WarnOnGitVersion(); if (ShouldRenameRemote) return helper.Run(this); @@ -142,7 +140,7 @@ public int Run(string param1, string param2) VerifyCloneAllRepository(); - globals.WarnOnGitVersion(stdout); + globals.WarnOnGitVersion(); if (ShouldDeleteRemote) return helper.Run(this); @@ -172,20 +170,20 @@ private int RenameRemote(string oldRemoteName, string newRemoteName) { var newRemoteNameExpected = globals.Repository.AssertValidBranchName(newRemoteName.ToGitRefName()); if (newRemoteNameExpected != newRemoteName) - stdout.WriteLine("The name of the branch after renaming will be : " + newRemoteNameExpected); + Trace.TraceInformation("The name of the branch after renaming will be : " + newRemoteNameExpected); if (globals.Repository.HasRemote(newRemoteNameExpected)) { throw new GitTfsException("error: this remote name is already used!"); } - stdout.WriteLine("Cleaning before processing rename..."); + Trace.TraceInformation("Cleaning before processing rename..."); cleanup.Run(); globals.Repository.MoveRemote(oldRemoteName, newRemoteNameExpected); if(globals.Repository.RenameBranch(oldRemoteName, newRemoteName) == null) - stdout.WriteLine("warning: no local branch found to rename"); + Trace.TraceWarning("warning: no local branch found to rename"); return GitTfsExitCodes.OK; } @@ -227,7 +225,7 @@ private int DeleteRemote(string remoteName) throw new GitTfsException(string.Format("Error: Remote \"{0}\" not found!", remoteName)); } - stdout.WriteLine("Cleaning before processing delete..."); + Trace.TraceInformation("Cleaning before processing delete..."); cleanup.Run(); globals.Repository.DeleteTfsRemote(remote); @@ -246,8 +244,8 @@ public int DisplayBranchData() { var remote = globals.Repository.ReadTfsRemote(remoteId); - stdout.WriteLine("\nTFS branch structure:"); - WriteRemoteTfsBranchStructure(remote.Tfs, stdout, remote.TfsRepositoryPath, tfsRemotes); + Trace.TraceInformation("\nTFS branch structure:"); + WriteRemoteTfsBranchStructure(remote.Tfs, remote.TfsRepositoryPath, tfsRemotes); return GitTfsExitCodes.OK; } else @@ -260,18 +258,18 @@ public int DisplayBranchData() foreach (var branch in remote.Tfs.GetBranches().Where(b=>b.IsRoot)) { var root = remote.Tfs.GetRootTfsBranchForRemotePath(branch.Path); - var visitor = new WriteBranchStructureTreeVisitor(remote.TfsRepositoryPath, stdout, tfsRemotes); + var visitor = new WriteBranchStructureTreeVisitor(remote.TfsRepositoryPath, tfsRemotes); root.AcceptVisitor(visitor); } return GitTfsExitCodes.OK; } } - WriteTfsRemoteDetails(stdout, tfsRemotes); + WriteTfsRemoteDetails(tfsRemotes); return GitTfsExitCodes.OK; } - public static void WriteRemoteTfsBranchStructure(ITfsHelper tfsHelper, TextWriter writer, string tfsRepositoryPath, IEnumerable tfsRemotes = null) + public static void WriteRemoteTfsBranchStructure(ITfsHelper tfsHelper, string tfsRepositoryPath, IEnumerable tfsRemotes = null) { var root = tfsHelper.GetRootTfsBranchForRemotePath(tfsRepositoryPath); @@ -279,59 +277,58 @@ public static void WriteRemoteTfsBranchStructure(ITfsHelper tfsHelper, TextWrite { throw new GitTfsException("error: this version of TFS doesn't support this functionality"); } - var visitor = new WriteBranchStructureTreeVisitor(tfsRepositoryPath, writer, tfsRemotes); + var visitor = new WriteBranchStructureTreeVisitor(tfsRepositoryPath, tfsRemotes); root.AcceptVisitor(visitor); } - private void WriteTfsRemoteDetails(TextWriter writer, IEnumerable tfsRemotes) + private void WriteTfsRemoteDetails(IEnumerable tfsRemotes) { - writer.WriteLine("\nGit-tfs remote details:"); + Trace.TraceInformation("\nGit-tfs remote details:"); foreach (var remote in tfsRemotes) { - writer.WriteLine("\n {0} -> {1} {2}", remote.Id, remote.TfsUrl, remote.TfsRepositoryPath); - writer.WriteLine(" {0} - {1} @ {2}", remote.RemoteRef, remote.MaxCommitHash, remote.MaxChangesetId); + Trace.TraceInformation("\n {0} -> {1} {2}", remote.Id, remote.TfsUrl, remote.TfsRepositoryPath); + Trace.TraceInformation(" {0} - {1} @ {2}", remote.RemoteRef, remote.MaxCommitHash, remote.MaxChangesetId); } } private class WriteBranchStructureTreeVisitor : IBranchTreeVisitor { - private readonly TextWriter _stdout; private readonly string _targetPath; private readonly IEnumerable _tfsRemotes; - public WriteBranchStructureTreeVisitor(string targetPath, TextWriter writer, IEnumerable tfsRemotes = null) + public WriteBranchStructureTreeVisitor(string targetPath, IEnumerable tfsRemotes = null) { _targetPath = targetPath; - _stdout = writer; _tfsRemotes = tfsRemotes; } public void Visit(BranchTree branch, int level) { + var writer = new StringWriter(); for (var i = 0; i < level; i++ ) - _stdout.Write(" | "); + writer.Write(" | "); - _stdout.WriteLine(); + writer.WriteLine(); for (var i = 0; i < level - 1; i++) - _stdout.Write(" | "); + writer.Write(" | "); if (level > 0) - _stdout.Write(" +-"); + writer.Write(" +-"); - _stdout.Write(" {0}", branch.Path); + writer.Write(" {0}", branch.Path); if (_tfsRemotes != null) { var remote = _tfsRemotes.FirstOrDefault(r => r.TfsRepositoryPath == branch.Path); if (remote != null) - _stdout.Write(" -> " + remote.Id); + writer.Write(" -> " + remote.Id); } if (branch.Path.Equals(_targetPath)) - _stdout.Write(" [*]"); + writer.Write(" [*]"); - _stdout.WriteLine(); + Trace.TraceInformation(writer.ToString()); } } } diff --git a/GitTfs/Commands/Checkin.cs b/GitTfs/Commands/Checkin.cs index 384a87ac1..c1235b9eb 100644 --- a/GitTfs/Commands/Checkin.cs +++ b/GitTfs/Commands/Checkin.cs @@ -10,8 +10,8 @@ namespace Sep.Git.Tfs.Commands [RequiresValidGitRepository] public class Checkin : CheckinBase { - public Checkin(TextWriter stdout, CheckinOptions checkinOptions, TfsWriter writer) - : base(stdout, checkinOptions, writer) + public Checkin(CheckinOptions checkinOptions, TfsWriter writer) + : base(checkinOptions, writer) { } diff --git a/GitTfs/Commands/CheckinBase.cs b/GitTfs/Commands/CheckinBase.cs index 8a4c8cd41..892e90b2c 100644 --- a/GitTfs/Commands/CheckinBase.cs +++ b/GitTfs/Commands/CheckinBase.cs @@ -9,13 +9,11 @@ namespace Sep.Git.Tfs.Commands { public abstract class CheckinBase : GitTfsCommand { - private readonly TextWriter _stdout; protected readonly CheckinOptions _checkinOptions; private readonly TfsWriter _writer; - protected CheckinBase(TextWriter stdout, CheckinOptions checkinOptions, TfsWriter writer) + protected CheckinBase(CheckinOptions checkinOptions, TfsWriter writer) { - _stdout = stdout; _checkinOptions = checkinOptions; _writer = writer; } @@ -41,12 +39,12 @@ private int PerformCheckin(TfsChangesetInfo parentChangeset, string refToCheckin if (_checkinOptions.NoMerge) { - _stdout.WriteLine("TFS Changeset #" + newChangesetId + " was created."); + Trace.TraceInformation("TFS Changeset #" + newChangesetId + " was created."); parentChangeset.Remote.Fetch(); } else { - _stdout.WriteLine("TFS Changeset #" + newChangesetId + " was created. Marking it as a merge commit..."); + Trace.TraceInformation("TFS Changeset #" + newChangesetId + " was created. Marking it as a merge commit..."); parentChangeset.Remote.FetchWithMerge(newChangesetId, false, refToCheckin); if (refToCheckin == "HEAD") diff --git a/GitTfs/Commands/CheckinTool.cs b/GitTfs/Commands/CheckinTool.cs index 2c3752123..8e922925a 100644 --- a/GitTfs/Commands/CheckinTool.cs +++ b/GitTfs/Commands/CheckinTool.cs @@ -10,7 +10,7 @@ namespace Sep.Git.Tfs.Commands [RequiresValidGitRepository] public class CheckinTool : CheckinBase { - public CheckinTool(TextWriter stdout, CheckinOptions checkinOptions, TfsWriter writer) : base(stdout, checkinOptions, writer) + public CheckinTool(CheckinOptions checkinOptions, TfsWriter writer) : base(checkinOptions, writer) { } diff --git a/GitTfs/Commands/Checkout.cs b/GitTfs/Commands/Checkout.cs index ac05851ad..db7e830c7 100644 --- a/GitTfs/Commands/Checkout.cs +++ b/GitTfs/Commands/Checkout.cs @@ -5,6 +5,7 @@ using NDesk.Options; using Sep.Git.Tfs.Core; using StructureMap; +using System.Diagnostics; namespace Sep.Git.Tfs.Commands { @@ -14,12 +15,10 @@ namespace Sep.Git.Tfs.Commands public class Checkout : GitTfsCommand { private readonly Globals _globals; - private readonly TextWriter _stdout; - public Checkout(Globals globals, TextWriter stdout) + public Checkout(Globals globals) { _globals = globals; - _stdout = stdout; } public OptionSet OptionSet @@ -48,7 +47,7 @@ public int Run(string id) throw new GitTfsException("error: commit not found for this changeset id..."); if (ReturnShaOnly) { - _stdout.Write(sha); + Trace.TraceInformation(sha); return GitTfsExitCodes.OK; } string commitishToCheckout = sha; @@ -57,7 +56,7 @@ public int Run(string id) 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..."); + Trace.TraceInformation("Branch '" + BranchName + "' created..."); commitishToCheckout = BranchName; } if(!_globals.Repository.Checkout(commitishToCheckout)) diff --git a/GitTfs/Commands/CleanupWorkspaceLocal.cs b/GitTfs/Commands/CleanupWorkspaceLocal.cs index be5341b33..96894274b 100644 --- a/GitTfs/Commands/CleanupWorkspaceLocal.cs +++ b/GitTfs/Commands/CleanupWorkspaceLocal.cs @@ -5,6 +5,7 @@ using NDesk.Options; using Sep.Git.Tfs.Core; using StructureMap; +using System.Diagnostics; namespace Sep.Git.Tfs.Commands { @@ -13,13 +14,11 @@ namespace Sep.Git.Tfs.Commands [RequiresValidGitRepository] public class CleanupWorkspaceLocal : GitTfsCommand { - private readonly TextWriter _stdout; private readonly Globals _globals; private readonly CleanupOptions _cleanupOptions; - public CleanupWorkspaceLocal(TextWriter stdout, Globals globals, CleanupOptions cleanupOptions) + public CleanupWorkspaceLocal(Globals globals, CleanupOptions cleanupOptions) { - _stdout = stdout; _globals = globals; _cleanupOptions = cleanupOptions; } @@ -52,7 +51,7 @@ public int Run(IList remoteIds) private void Cleanup(IGitTfsRemote remote) { - _stdout.WriteLine("Cleaning up workspaces directory for TFS remote " + remote.Id); + Trace.TraceInformation("Cleaning up workspaces directory for TFS remote " + remote.Id); remote.CleanupWorkspaceDirectory(); } } diff --git a/GitTfs/Commands/CleanupWorkspaces.cs b/GitTfs/Commands/CleanupWorkspaces.cs index e2758ea63..d01a9fbb9 100644 --- a/GitTfs/Commands/CleanupWorkspaces.cs +++ b/GitTfs/Commands/CleanupWorkspaces.cs @@ -5,6 +5,7 @@ using NDesk.Options; using Sep.Git.Tfs.Core; using StructureMap; +using System.Diagnostics; namespace Sep.Git.Tfs.Commands { @@ -13,13 +14,11 @@ namespace Sep.Git.Tfs.Commands [RequiresValidGitRepository] public class CleanupWorkspaces : GitTfsCommand { - private readonly TextWriter _stdout; private readonly Globals _globals; private readonly CleanupOptions _cleanupOptions; - public CleanupWorkspaces(TextWriter stdout, Globals globals, CleanupOptions cleanupOptions) + public CleanupWorkspaces(Globals globals, CleanupOptions cleanupOptions) { - _stdout = stdout; _globals = globals; _cleanupOptions = cleanupOptions; } @@ -52,7 +51,7 @@ public int Run(IList remoteIds) private void Cleanup(IGitTfsRemote remote) { - _stdout.WriteLine("Cleaning up workspaces for TFS remote " + remote.Id); + Trace.TraceInformation("Cleaning up workspaces for TFS remote " + remote.Id); remote.CleanupWorkspace(); } } diff --git a/GitTfs/Commands/Clone.cs b/GitTfs/Commands/Clone.cs index e088908bb..513927635 100644 --- a/GitTfs/Commands/Clone.cs +++ b/GitTfs/Commands/Clone.cs @@ -22,15 +22,13 @@ public class Clone : GitTfsCommand private readonly Globals globals; private readonly InitBranch initBranch; private bool resumable; - private TextWriter stdout; - public Clone(Globals globals, Fetch fetch, Init init, InitBranch initBranch, TextWriter stdout) + public Clone(Globals globals, Fetch fetch, Init init, InitBranch initBranch) { this.fetch = fetch; this.init = init; this.globals = globals; this.initBranch = initBranch; - this.stdout = stdout; globals.GcCountdown = globals.GcPeriod; } @@ -176,7 +174,7 @@ private void VerifyTfsPathToClone(string tfsRepositoryPath) var tfsRootBranches = remote.Tfs.GetAllTfsRootBranchesOrderedByCreation(); if (!tfsRootBranches.Any()) { - stdout.WriteLine("info: no TFS root found !\n\nPS:perhaps you should convert your trunk folder into a branch in TFS."); + Trace.TraceInformation("info: no TFS root found !\n\nPS:perhaps you should convert your trunk folder into a branch in TFS."); return; } var cloneMsg = " => If you want to manage branches with git-tfs, clone one of this branch instead :\n" @@ -185,7 +183,7 @@ private void VerifyTfsPathToClone(string tfsRepositoryPath) if (fetch.BranchStrategy == BranchStrategy.All) throw new GitTfsException("error: cloning the whole repository or too high in the repository path doesn't permit to manage branches!\n" + cloneMsg); - stdout.WriteLine("warning: you are going to clone the whole repository or too high in the repository path !\n" + cloneMsg); + Trace.TraceWarning("warning: you are going to clone the whole repository or too high in the repository path !\n" + cloneMsg); return; } @@ -195,10 +193,10 @@ private void VerifyTfsPathToClone(string tfsRepositoryPath) if (tfsPathToClone != tfsTrunkRepositoryPath.ToLower()) { if (tfsBranchesPath.Select(e=>e.Path.ToLower()).Contains(tfsPathToClone)) - stdout.WriteLine("info: you are going to clone a branch instead of the trunk ( {0} )\n" + Trace.TraceInformation("info: you are going to clone a branch instead of the trunk ( {0} )\n" + " => If you want to manage branches with git-tfs, clone {0} with '--branches=all' option instead...)", tfsTrunkRepositoryPath); else - stdout.WriteLine("warning: you are going to clone a subdirectory of a branch and won't be able to manage branches :(\n" + Trace.TraceWarning("warning: you are going to clone a subdirectory of a branch and won't be able to manage branches :(\n" + " => If you want to manage branches with git-tfs, clone " + tfsTrunkRepositoryPath + " with '--branches=all' option instead...)"); } } @@ -208,7 +206,7 @@ private void VerifyTfsPathToClone(string tfsRepositoryPath) } catch (Exception ex) { - stdout.WriteLine("warning: a server error occurs when trying to verify the tfs path cloned:\n " + ex.Message + Trace.TraceWarning("warning: a server error occurs when trying to verify the tfs path cloned:\n " + ex.Message + "\n try to continue anyway..."); } } diff --git a/GitTfs/Commands/Create.cs b/GitTfs/Commands/Create.cs index 35762b87f..908853c0b 100644 --- a/GitTfs/Commands/Create.cs +++ b/GitTfs/Commands/Create.cs @@ -3,6 +3,7 @@ using NDesk.Options; using StructureMap; using Sep.Git.Tfs.Core.TfsInterop; +using System.Diagnostics; namespace Sep.Git.Tfs.Commands { @@ -14,15 +15,13 @@ namespace Sep.Git.Tfs.Commands public class Create : GitTfsCommand { private readonly Clone _clone; - private readonly TextWriter _stdout; private readonly ITfsHelper _tfsHelper; private readonly RemoteOptions _remoteOptions; private string _trunkName = "trunk"; private bool _createTeamProjectFolder; - public Create(ITfsHelper tfsHelper, Clone clone, RemoteOptions remoteOptions, TextWriter stdout) + public Create(ITfsHelper tfsHelper, Clone clone, RemoteOptions remoteOptions) { - _stdout = stdout; _tfsHelper = tfsHelper; _clone = clone; _remoteOptions = remoteOptions; @@ -52,9 +51,9 @@ public int Run(string tfsUrl, string projectName, string gitRepositoryPath) _tfsHelper.Password = _remoteOptions.Password; var absoluteGitRepositoryPath = Path.GetFullPath(gitRepositoryPath); - _stdout.WriteLine("Creating project folder..."); + Trace.TraceInformation("Creating project folder..."); _tfsHelper.CreateTfsRootBranch(projectName, _trunkName, absoluteGitRepositoryPath, _createTeamProjectFolder); - _stdout.WriteLine("Cloning new project..."); + Trace.TraceInformation("Cloning new project..."); _clone.Run(tfsUrl, "$/" + projectName + "/" + _trunkName, gitRepositoryPath); return GitTfsExitCodes.OK; diff --git a/GitTfs/Commands/Diagnostics.cs b/GitTfs/Commands/Diagnostics.cs index 19a777636..23eba63c5 100644 --- a/GitTfs/Commands/Diagnostics.cs +++ b/GitTfs/Commands/Diagnostics.cs @@ -3,18 +3,17 @@ using System.IO; using NDesk.Options; using StructureMap; +using System.Diagnostics; namespace Sep.Git.Tfs.Commands { [Pluggable("diagnostics")] public class Diagnostics : GitTfsCommand { - private readonly TextWriter _stdout; private readonly IContainer _container; - public Diagnostics(TextWriter stdout, IContainer container) + public Diagnostics(IContainer container) { - _stdout = stdout; _container = container; } @@ -25,7 +24,7 @@ public OptionSet OptionSet public int Run() { - _stdout.WriteLine(_container.WhatDoIHave()); + Trace.TraceInformation(_container.WhatDoIHave()); return GitTfsExitCodes.OK; } } diff --git a/GitTfs/Commands/Fetch.cs b/GitTfs/Commands/Fetch.cs index 8b94b78a3..7503a9dbb 100644 --- a/GitTfs/Commands/Fetch.cs +++ b/GitTfs/Commands/Fetch.cs @@ -17,17 +17,15 @@ namespace Sep.Git.Tfs.Commands public class Fetch : GitTfsCommand { private readonly RemoteOptions remoteOptions; - private readonly TextWriter stdout; private readonly Globals globals; private readonly ConfigProperties properties; private readonly AuthorsFile authors; private readonly Labels labels; - public Fetch(Globals globals, ConfigProperties properties, TextWriter stdout, RemoteOptions remoteOptions, AuthorsFile authors, Labels labels) + public Fetch(Globals globals, ConfigProperties properties, RemoteOptions remoteOptions, AuthorsFile authors, Labels labels) { this.globals = globals; this.properties = properties; - this.stdout = stdout; this.remoteOptions = remoteOptions; this.authors = authors; this.labels = labels; @@ -35,8 +33,6 @@ public Fetch(Globals globals, ConfigProperties properties, TextWriter stdout, Re BranchStrategy = BranchStrategy = BranchStrategy.Auto; } - - bool FetchAll { get; set; } bool FetchLabels { get; set; } bool FetchParents { get; set; } @@ -142,11 +138,11 @@ private int Run(bool stopOnFailMergeCommit, params string[] args) private void FetchRemote(bool stopOnFailMergeCommit, IGitTfsRemote remote) { - stdout.WriteLine("Fetching from TFS remote '{0}'...", remote.Id); + Trace.TraceInformation("Fetching from TFS remote '{0}'...", remote.Id); DoFetch(remote, stopOnFailMergeCommit); if (labels != null && FetchLabels) { - stdout.WriteLine("Fetching labels from TFS remote '{0}'...", remote.Id); + Trace.TraceInformation("Fetching labels from TFS remote '{0}'...", remote.Id); labels.Run(remote); } } diff --git a/GitTfs/Commands/Help.cs b/GitTfs/Commands/Help.cs index 546c39045..bad275400 100644 --- a/GitTfs/Commands/Help.cs +++ b/GitTfs/Commands/Help.cs @@ -10,6 +10,7 @@ using StructureMap.Pipeline; using StructureMap.Query; using IContainer = StructureMap.IContainer; +using System.Diagnostics; namespace Sep.Git.Tfs.Commands { @@ -17,13 +18,11 @@ namespace Sep.Git.Tfs.Commands [Description("help [command-name]")] public class Help : GitTfsCommand { - private readonly TextWriter output; private readonly GitTfsCommandFactory commandFactory; private readonly IContainer _container; - public Help(TextWriter output, GitTfsCommandFactory commandFactory, IContainer container) + public Help(GitTfsCommandFactory commandFactory, IContainer container) { - this.output = output; this.commandFactory = commandFactory; _container = container; } @@ -39,7 +38,7 @@ public OptionSet OptionSet /// public int Run(IList args) { - foreach(var arg in args) + foreach (var arg in args) { var command = commandFactory.GetCommand(arg); if(command != null) @@ -48,7 +47,7 @@ public int Run(IList args) } else { - output.WriteLine("Invalid argument: " + arg); + Trace.TraceInformation("Invalid argument: " + arg); } } return Run(); @@ -59,22 +58,19 @@ public int Run(IList args) /// public int Run() { - output.WriteLine("Usage: git-tfs [command] [options]"); + Trace.TraceInformation("Usage: git-tfs [command] [options]"); foreach(var pair in GetCommandMap()) { - output.Write(" " + pair.Key); + var command = " " + pair.Key; if (pair.Value.Any()) { - output.WriteLine(" (" + string.Join(", ", pair.Value) + ")"); - } - else - { - output.WriteLine(); + command += " (" + string.Join(", ", pair.Value) + ")"; } + Trace.TraceInformation(command); } - output.WriteLine(" (use 'git-tfs help [command]' or 'git-tfs [command] --help' for more information)"); - output.WriteLine("\nFind more help in our online help : https://github.com/git-tfs/git-tfs"); + Trace.TraceInformation(" (use 'git-tfs help [command]' or 'git-tfs [command] --help' for more information)"); + Trace.TraceInformation("\nFind more help in our online help : https://github.com/git-tfs/git-tfs"); return GitTfsExitCodes.Help; } @@ -86,10 +82,12 @@ public int Run(GitTfsCommand command) if (command is Help) return Run(); - output.WriteLine("Usage: git-tfs " + GetCommandUsage(command)); - command.GetAllOptions(_container).WriteOptionDescriptions(output); + Trace.TraceInformation("Usage: git-tfs " + GetCommandUsage(command)); + var writer = new StringWriter(); + command.GetAllOptions(_container).WriteOptionDescriptions(writer); + Trace.TraceInformation(writer.ToString()); - output.WriteLine("\nFind more help in our online help : https://github.com/git-tfs/git-tfs/blob/master/doc/commands/" + GetCommandName(command)+".md"); + Trace.TraceInformation("\nFind more help in our online help : https://github.com/git-tfs/git-tfs/blob/master/doc/commands/" + GetCommandName(command)+".md"); return GitTfsExitCodes.Help; } diff --git a/GitTfs/Commands/Info.cs b/GitTfs/Commands/Info.cs index 5c68584a3..c61558485 100644 --- a/GitTfs/Commands/Info.cs +++ b/GitTfs/Commands/Info.cs @@ -14,13 +14,11 @@ namespace Sep.Git.Tfs.Commands public class Info : GitTfsCommand { readonly Globals _globals; - readonly TextWriter _stdout; readonly IGitTfsVersionProvider _versionProvider; - public Info(Globals globals, TextWriter stdout, IGitTfsVersionProvider versionProvider) + public Info(Globals globals, IGitTfsVersionProvider versionProvider) { _globals = globals; - _stdout = stdout; _versionProvider = versionProvider; } @@ -45,16 +43,16 @@ private void DescribeGit() { DisplayReadabilityLineJump(); - _stdout.WriteLine(_globals.GitVersion); + Trace.TraceInformation(_globals.GitVersion); } private void DescribeGitTfs() { DisplayReadabilityLineJump(); - _stdout.WriteLine(_versionProvider.GetVersionString()); - _stdout.WriteLine(" " + _versionProvider.GetPathToGitTfsExecutable()); + Trace.TraceInformation(_versionProvider.GetVersionString()); + Trace.TraceInformation(" " + _versionProvider.GetPathToGitTfsExecutable()); - _stdout.WriteLine(GitTfsConstants.MessageForceVersion); + Trace.TraceInformation(GitTfsConstants.MessageForceVersion); DescribeGitRepository(); } @@ -69,7 +67,7 @@ private void DescribeGitRepository() DisplayReadabilityLineJump(); - _stdout.WriteLine("cloned from tfs path:" + string.Join(Environment.NewLine, repoDescription)); + Trace.TraceInformation("cloned from tfs path:" + string.Join(Environment.NewLine, repoDescription)); } catch (Exception) { @@ -80,13 +78,13 @@ private void DescribeGitRepository() private void DescribeTfsRemotes(IGitTfsRemote remote) { DisplayReadabilityLineJump(); - _stdout.WriteLine("remote tfs id: '{0}' {1} {2}", remote.Id, remote.TfsUrl, remote.TfsRepositoryPath); - _stdout.WriteLine(" {0} - {1} @ {2}", remote.RemoteRef, remote.MaxCommitHash, remote.MaxChangesetId); + Trace.TraceInformation("remote tfs id: '{0}' {1} {2}", remote.Id, remote.TfsUrl, remote.TfsRepositoryPath); + Trace.TraceInformation(" {0} - {1} @ {2}", remote.RemoteRef, remote.MaxCommitHash, remote.MaxChangesetId); } private void DisplayReadabilityLineJump() { - _stdout.WriteLine(); + Trace.TraceInformation(string.Empty); } } } diff --git a/GitTfs/Commands/Init.cs b/GitTfs/Commands/Init.cs index a2b900e02..89b596835 100644 --- a/GitTfs/Commands/Init.cs +++ b/GitTfs/Commands/Init.cs @@ -17,16 +17,14 @@ public class Init : GitTfsCommand private readonly InitOptions initOptions; private readonly RemoteOptions remoteOptions; private readonly Globals globals; - private readonly TextWriter output; private readonly IGitHelpers gitHelper; private readonly IHelpHelper _help; - public Init(RemoteOptions remoteOptions, InitOptions initOptions, Globals globals, TextWriter output, IGitHelpers gitHelper, IHelpHelper help) + public Init(RemoteOptions remoteOptions, InitOptions initOptions, Globals globals, IGitHelpers gitHelper, IHelpHelper help) { this.remoteOptions = remoteOptions; this.gitHelper = gitHelper; _help = help; - this.output = output; this.globals = globals; this.initOptions = initOptions; } diff --git a/GitTfs/Commands/InitBranch.cs b/GitTfs/Commands/InitBranch.cs index fefa46cf2..33f98dc97 100644 --- a/GitTfs/Commands/InitBranch.cs +++ b/GitTfs/Commands/InitBranch.cs @@ -14,7 +14,6 @@ namespace Sep.Git.Tfs.Commands { public class InitBranch : GitTfsCommand { - private readonly TextWriter _stdout; private readonly Globals _globals; private readonly Help _helper; private readonly AuthorsFile _authors; @@ -31,9 +30,8 @@ public class InitBranch : GitTfsCommand public IGitTfsRemote RemoteCreated { get; private set; } - public InitBranch(TextWriter stdout, Globals globals, Help helper, AuthorsFile authors) + public InitBranch(Globals globals, Help helper, AuthorsFile authors) { - _stdout = stdout; _globals = globals; _helper = helper; _authors = authors; @@ -106,7 +104,7 @@ private int CloneBranch(string tfsBranchPath, string gitBranchNameExpected) var remote = allRemotes.FirstOrDefault(r => r.TfsRepositoryPath.ToLower() == tfsBranchPath.ToLower()); if (remote != null && remote.MaxChangesetId != 0) { - _stdout.WriteLine("warning : There is already a remote for this tfs branch. Branch ignored!"); + Trace.TraceInformation("warning : There is already a remote for this tfs branch. Branch ignored!"); return GitTfsExitCodes.InvalidArguments; } @@ -133,9 +131,9 @@ private IGitTfsRemote InitBranchSupportingRename(string tfsBranchPath, string gi RemoveAlreadyFetchedBranches(creationBranchData, defaultRemote); - _stdout.WriteLine("Branches to Initialize successively :"); + Trace.TraceInformation("Branches to Initialize successively :"); foreach (var branch in creationBranchData) - _stdout.WriteLine("-" + branch.TfsBranchPath + " (" + branch.RootChangeset + ")"); + Trace.TraceInformation("-" + branch.TfsBranchPath + " (" + branch.RootChangeset + ")"); IGitTfsRemote tfsRemote = null; var remoteToDelete = new List(); @@ -221,7 +219,7 @@ private int CloneAll(string gitRemote) } else { - _stdout.WriteLine("No other Tfs branches found."); + Trace.TraceInformation("No other Tfs branches found."); } } else @@ -246,7 +244,7 @@ private int CloneAll(string gitRemote) } else { - _stdout.WriteLine("No other Tfs branches found."); + Trace.TraceInformation("No other Tfs branches found."); } } return GitTfsExitCodes.OK; @@ -264,11 +262,11 @@ private static List GetChildBranchesToInit(IGitTfsRemote defaultRem private void InitializeBranches(IGitTfsRemote defaultRemote, List childBranchPaths) { - _stdout.WriteLine("Tfs branches found:"); + Trace.TraceInformation("Tfs branches found:"); var branchesToProcess = new List(); foreach (var tfsBranchPath in childBranchPaths) { - _stdout.WriteLine("- " + tfsBranchPath.TfsRepositoryPath); + Trace.TraceInformation("- " + tfsBranchPath.TfsRepositoryPath); var branchDatas = new BranchDatas { TfsRepositoryPath = tfsBranchPath.TfsRepositoryPath, @@ -294,7 +292,7 @@ private void InitializeBranches(IGitTfsRemote defaultRemote, List c var branchesToFetch = branchesToProcess.Where(b => !b.IsEntirelyFetched && b.Error == null).ToList(); foreach (var tfsBranch in branchesToFetch) { - _stdout.WriteLine("=> Working on TFS branch : " + tfsBranch.TfsRepositoryPath); + Trace.TraceInformation("=> Working on TFS branch : " + tfsBranch.TfsRepositoryPath); if (tfsBranch.TfsRemote == null || tfsBranch.TfsRemote.MaxChangesetId == 0) { try @@ -310,7 +308,7 @@ private void InitializeBranches(IGitTfsRemote defaultRemote, List c } catch (Exception ex) { - _stdout.WriteLine("error: an error occurs when initializing the branch. Branch is ignored and continuing..."); + Trace.TraceInformation("error: an error occurs when initializing the branch. Branch is ignored and continuing..."); tfsBranch.Error = ex; } } @@ -327,7 +325,7 @@ private void InitializeBranches(IGitTfsRemote defaultRemote, List c } catch (Exception ex) { - _stdout.WriteLine("error: an error occurs when fetching changeset. Fetching is stopped and continuing..."); + Trace.TraceInformation("error: an error occurs when fetching changeset. Fetching is stopped and continuing..."); tfsBranch.Error = ex; } } @@ -338,25 +336,25 @@ private void InitializeBranches(IGitTfsRemote defaultRemote, List c if (branchesToProcess.Any(b => !b.IsEntirelyFetched)) { - _stdout.WriteLine("warning: Some Tfs branches could not have been initialized:"); + Trace.TraceWarning("warning: Some Tfs branches could not have been initialized:"); foreach (var branchNotInited in branchesToProcess.Where(b => !b.IsEntirelyFetched)) { - _stdout.WriteLine("- " + branchNotInited.TfsRepositoryPath); + Trace.TraceInformation("- " + branchNotInited.TfsRepositoryPath); } - _stdout.WriteLine("\nPlease report this case to the git-tfs developers! (report here : https://github.com/git-tfs/git-tfs/issues/461 )"); + Trace.TraceInformation("\nPlease report this case to the git-tfs developers! (report here : https://github.com/git-tfs/git-tfs/issues/461 )"); } if (branchesToProcess.Any(b => b.Error != null)) { - _stdout.WriteLine("warning: Some Tfs branches could not have been initialized or entirely fetched due to errors:"); + Trace.TraceWarning("warning: Some Tfs branches could not have been initialized or entirely fetched due to errors:"); foreach (var branchWithErrors in branchesToProcess.Where(b => b.Error != null)) { - _stdout.WriteLine("- " + branchWithErrors.TfsRepositoryPath); + Trace.TraceInformation("- " + branchWithErrors.TfsRepositoryPath); if (_globals.DebugOutput) Trace.WriteLine(" =>error:" + branchWithErrors.Error); else - _stdout.WriteLine(" =>error:" + branchWithErrors.Error.Message); + Trace.TraceInformation(" =>error:" + branchWithErrors.Error.Message); } - _stdout.WriteLine("\nPlease report this case to the git-tfs developers! (report here : https://github.com/git-tfs/git-tfs/issues )"); + Trace.TraceInformation("\nPlease report this case to the git-tfs developers! (report here : https://github.com/git-tfs/git-tfs/issues )"); } } @@ -413,13 +411,13 @@ private IFetchResult FetchRemote(IGitTfsRemote tfsRemote, bool stopOnFailMergeCo if (!_globals.Repository.HasRef(branchRef)) { if (!_globals.Repository.CreateBranch(branchRef, tfsRemote.MaxCommitHash)) - _stdout.WriteLine("warning: Fail to create local branch ref file!"); + Trace.TraceWarning("warning: Fail to create local branch ref file!"); else Trace.WriteLine("Local branch created!"); } else { - _stdout.WriteLine("info: local branch ref already exists!"); + Trace.TraceInformation("info: local branch ref already exists!"); } } return fetchResult; diff --git a/GitTfs/Commands/Labels.cs b/GitTfs/Commands/Labels.cs index fb39a237c..8f254d4df 100644 --- a/GitTfs/Commands/Labels.cs +++ b/GitTfs/Commands/Labels.cs @@ -16,7 +16,6 @@ namespace Sep.Git.Tfs.Commands [RequiresValidGitRepository] public class Labels : GitTfsCommand { - private readonly TextWriter _stdout; private readonly Globals _globals; private readonly AuthorsFile _authors; @@ -27,9 +26,8 @@ public class Labels : GitTfsCommand public string NameFilter { get; set; } public string ExcludeNameFilter { get; set; } - public Labels(TextWriter stdout, Globals globals, AuthorsFile authors) + public Labels(Globals globals, AuthorsFile authors) { - this._stdout = stdout; this._globals = globals; this._authors = authors; } @@ -87,9 +85,9 @@ private int CreateLabelsForTfsBranch(IGitTfsRemote tfsRemote) NameFilter = NameFilter.Trim(); UpdateRemote(tfsRemote); - _stdout.WriteLine("Looking for label on " + tfsRemote.TfsRepositoryPath + "..."); + Trace.TraceInformation("Looking for label on " + tfsRemote.TfsRepositoryPath + "..."); var labels = tfsRemote.Tfs.GetLabels(tfsRemote.TfsRepositoryPath, NameFilter); - _stdout.WriteLine(labels.Count() +" labels found!"); + Trace.TraceInformation(labels.Count() +" labels found!"); Regex exludeRegex = null; if (ExcludeNameFilter != null) @@ -124,7 +122,7 @@ private int CreateLabelsForTfsBranch(IGitTfsRemote tfsRemote) ownerEmail = label.Owner; } var labelName = (label.IsTransBranch ? label.Name + "(" + tfsRemote.Id + ")" : label.Name).ToGitRefName(); - _stdout.WriteLine("Writing label '" + labelName + "'..."); + Trace.TraceInformation("Writing label '" + labelName + "'..."); _globals.Repository.CreateTag(labelName, sha1TagCommit, label.Comment, ownerName, ownerEmail ,label.Date); } return GitTfsExitCodes.OK; diff --git a/GitTfs/Commands/ListRemoteBranches.cs b/GitTfs/Commands/ListRemoteBranches.cs index 41ed1b301..9e2ca1167 100644 --- a/GitTfs/Commands/ListRemoteBranches.cs +++ b/GitTfs/Commands/ListRemoteBranches.cs @@ -5,6 +5,7 @@ using StructureMap; using Sep.Git.Tfs.Core; using Sep.Git.Tfs.Core.TfsInterop; +using System.Diagnostics; namespace Sep.Git.Tfs.Commands { @@ -15,12 +16,10 @@ public class ListRemoteBranches : GitTfsCommand private readonly Globals globals; private readonly ITfsHelper tfsHelper; private readonly RemoteOptions remoteOptions; - private TextWriter stdout; - public ListRemoteBranches(Globals globals, TextWriter stdout, ITfsHelper tfsHelper, RemoteOptions remoteOptions) + public ListRemoteBranches(Globals globals, ITfsHelper tfsHelper, RemoteOptions remoteOptions) { this.globals = globals; - this.stdout = stdout; this.tfsHelper = tfsHelper; this.remoteOptions = remoteOptions; } @@ -45,23 +44,25 @@ public int Run(string tfsUrl) throw new GitTfsException("error: this version of TFS doesn't support this functionality"); } + string convertBranchMessage = " -> Open 'Source Control Explorer' and for each folder corresponding to a branch, right click on the folder and select 'Branching and Merging' > 'Convert to branch'."; var branches = tfsHelper.GetBranches().Where(b => b.IsRoot).ToList(); if (branches.IsEmpty()) { - stdout.WriteLine("No TFS branches were found!"); - stdout.WriteLine("\n\nPerhaps you should convert your branch folders into a branch in TFS:"); + Trace.TraceWarning("No TFS branches were found!"); + Trace.TraceWarning("\n\nPerhaps you should convert your branch folders into a branch in TFS:"); + Trace.TraceWarning(convertBranchMessage); } else { - stdout.WriteLine("TFS branches that could be cloned:"); + Trace.TraceInformation("TFS branches that could be cloned:"); foreach (var branchObject in branches.Where(b => b.IsRoot)) { - Branch.WriteRemoteTfsBranchStructure(tfsHelper, stdout, branchObject.Path); + Branch.WriteRemoteTfsBranchStructure(tfsHelper, branchObject.Path); } - stdout.WriteLine("\nCloning root branches (marked by [*]) is recommended!"); - stdout.WriteLine("\n\nPS:if your branch is not listed here, perhaps you should convert its containing folder into a branch in TFS:"); + Trace.TraceInformation("\nCloning root branches (marked by [*]) is recommended!"); + Trace.TraceInformation("\n\nPS:if your branch is not listed here, perhaps you should convert its containing folder into a branch in TFS:"); + Trace.TraceInformation(convertBranchMessage); } - stdout.WriteLine(" -> Open 'Source Control Explorer' and for each folder corresponding to a branch, right click on the folder and select 'Branching and Merging' > 'Convert to branch'."); return GitTfsExitCodes.OK; } } diff --git a/GitTfs/Commands/Pull.cs b/GitTfs/Commands/Pull.cs index a4ba22fa2..17c91d710 100644 --- a/GitTfs/Commands/Pull.cs +++ b/GitTfs/Commands/Pull.cs @@ -15,7 +15,6 @@ public class Pull : GitTfsCommand { private readonly Fetch fetch; private readonly Globals globals; - private TextWriter stdout; private bool _shouldRebase; public OptionSet OptionSet @@ -27,11 +26,10 @@ public OptionSet OptionSet } } - public Pull(Globals globals, Fetch fetch, TextWriter stdout) + public Pull(Globals globals, Fetch fetch) { this.fetch = fetch; this.globals = globals; - this.stdout = stdout; } public int Run() @@ -48,7 +46,7 @@ public int Run(string remoteId) var remote = globals.Repository.ReadTfsRemote(remoteId); if (_shouldRebase) { - globals.WarnOnGitVersion(stdout); + globals.WarnOnGitVersion(); if (globals.Repository.WorkingCopyHasUnstagedOrUncommitedChanges) { diff --git a/GitTfs/Commands/QuickClone.cs b/GitTfs/Commands/QuickClone.cs index 79f1b5a54..5cbe809b8 100644 --- a/GitTfs/Commands/QuickClone.cs +++ b/GitTfs/Commands/QuickClone.cs @@ -8,8 +8,8 @@ namespace Sep.Git.Tfs.Commands [Description("quick-clone [options] tfs-url-or-instance-name repository-path ")] public class QuickClone : Clone { - public QuickClone(Globals globals, Init init, QuickFetch fetch, TextWriter stdout) - : base(globals, fetch, init, null, stdout) + public QuickClone(Globals globals, Init init, QuickFetch fetch) + : base(globals, fetch, init, null) { } } diff --git a/GitTfs/Commands/QuickFetch.cs b/GitTfs/Commands/QuickFetch.cs index 0856e9cee..9c0906b4f 100644 --- a/GitTfs/Commands/QuickFetch.cs +++ b/GitTfs/Commands/QuickFetch.cs @@ -17,8 +17,8 @@ namespace Sep.Git.Tfs.Commands public class QuickFetch : Fetch { private ConfigProperties _properties; - public QuickFetch(Globals globals, ConfigProperties properties, TextWriter stdout, RemoteOptions remoteOptions, AuthorsFile authors) - : base(globals, properties, stdout, remoteOptions, authors, null) + public QuickFetch(Globals globals, ConfigProperties properties, RemoteOptions remoteOptions, AuthorsFile authors) + : base(globals, properties, remoteOptions, authors, null) { _properties = properties; } diff --git a/GitTfs/Commands/Rcheckin.cs b/GitTfs/Commands/Rcheckin.cs index f44289de0..ef1ee1699 100644 --- a/GitTfs/Commands/Rcheckin.cs +++ b/GitTfs/Commands/Rcheckin.cs @@ -14,7 +14,6 @@ namespace Sep.Git.Tfs.Commands [RequiresValidGitRepository] public class Rcheckin : GitTfsCommand { - private readonly TextWriter _stdout; private readonly CheckinOptions _checkinOptions; private readonly CheckinOptionsFactory _checkinOptionsFactory; private readonly TfsWriter _writer; @@ -24,11 +23,10 @@ public class Rcheckin : GitTfsCommand private bool AutoRebase { get; set; } private bool ForceCheckin { get; set; } - public Rcheckin(TextWriter stdout, CheckinOptions checkinOptions, TfsWriter writer, Globals globals, AuthorsFile authors) + public Rcheckin(CheckinOptions checkinOptions, TfsWriter writer, Globals globals, AuthorsFile authors) { - _stdout = stdout; _checkinOptions = checkinOptions; - _checkinOptionsFactory = new CheckinOptionsFactory(_stdout, globals); + _checkinOptionsFactory = new CheckinOptionsFactory(globals); _writer = writer; _globals = globals; _authors = authors; @@ -49,7 +47,7 @@ public OptionSet OptionSet // uses rebase and works only with HEAD public int Run() { - _globals.WarnOnGitVersion(_stdout); + _globals.WarnOnGitVersion(); if (_globals.Repository.IsBare) throw new GitTfsException("error: you should specify the local branch to checkin for a bare repository."); @@ -60,7 +58,7 @@ public int Run() // uses rebase and works only with HEAD in a none bare repository public int Run(string localBranch) { - _globals.WarnOnGitVersion(_stdout); + _globals.WarnOnGitVersion(); if (!_globals.Repository.IsBare) throw new GitTfsException("error: This syntax with one parameter is only allowed in bare repository."); @@ -82,7 +80,7 @@ private int PerformRCheckin(TfsChangesetInfo parentChangeset, string refToChecki } // get latest changes from TFS to minimize possibility of late conflict - _stdout.WriteLine("Fetching changes from TFS to minimize possibility of late conflict..."); + Trace.TraceInformation("Fetching changes from TFS to minimize possibility of late conflict..."); parentChangeset.Remote.Fetch(); if (parentChangeset.ChangesetId != parentChangeset.Remote.MaxChangesetId) { @@ -135,7 +133,7 @@ private int _PerformRCheckinQuick(TfsChangesetInfo parentChangeset, string refTo var commitSpecificCheckinOptions = _checkinOptionsFactory.BuildCommitSpecificCheckinOptions(_checkinOptions, message, commit, _authors); - _stdout.WriteLine("Starting checkin of {0} '{1}'", target.Substring(0, 8), commitSpecificCheckinOptions.CheckinComment); + Trace.TraceInformation("Starting checkin of {0} '{1}'", target.Substring(0, 8), commitSpecificCheckinOptions.CheckinComment); try { newChangesetId = tfsRemote.Checkin(target, currentParent, parentChangeset, commitSpecificCheckinOptions, tfsRepositoryPathOfMergedBranch); @@ -152,7 +150,7 @@ private int _PerformRCheckinQuick(TfsChangesetInfo parentChangeset, string refTo currentParent = target; parentChangeset = new TfsChangesetInfo {ChangesetId = newChangesetId, GitCommit = tfsRemote.MaxCommitHash, Remote = tfsRemote}; - _stdout.WriteLine("Done with {0}.", target); + Trace.TraceInformation("Done with {0}.", target); } catch (Exception) { @@ -169,7 +167,7 @@ private int _PerformRCheckinQuick(TfsChangesetInfo parentChangeset, string refTo _globals.Repository.UpdateRef(refToCheckin, tfsRemote.MaxCommitHash); else _globals.Repository.ResetHard(tfsRemote.MaxCommitHash); - _stdout.WriteLine("No more to rcheckin."); + Trace.TraceInformation("No more to rcheckin."); Trace.WriteLine("Cleaning..."); tfsRemote.CleanupWorkspaceDirectory(); @@ -188,9 +186,9 @@ private string FindTfsRepositoryPathOfMergedBranch(IGitTfsRemote remoteToCheckin { if (gitParents.Length != 0) { - _stdout.WriteLine("Working on the merge commit: " + target); + Trace.TraceInformation("Working on the merge commit: " + target); if (gitParents.Length > 1) - _stdout.WriteLine("warning: only 1 parent is supported by TFS for a merge changeset. The other parents won't be materialized in the TFS merge!"); + Trace.TraceWarning("warning: only 1 parent is supported by TFS for a merge changeset. The other parents won't be materialized in the TFS merge!"); foreach (var gitParent in gitParents) { var tfsCommit = _globals.Repository.GetTfsCommit(gitParent); @@ -208,7 +206,7 @@ private string FindTfsRepositoryPathOfMergedBranch(IGitTfsRemote remoteToCheckin } else { - _stdout.WriteLine("warning: the parent " + gitParent + " does not belong to a TFS tracked branch (not checked in TFS) and will be ignored!"); + Trace.TraceWarning("warning: the parent " + gitParent + " does not belong to a TFS tracked branch (not checked in TFS) and will be ignored!"); } } } diff --git a/GitTfs/Commands/ResetRemote.cs b/GitTfs/Commands/ResetRemote.cs index 8c5da5ece..3c78d6f7a 100644 --- a/GitTfs/Commands/ResetRemote.cs +++ b/GitTfs/Commands/ResetRemote.cs @@ -5,6 +5,7 @@ using NDesk.Options; using Sep.Git.Tfs.Core; using StructureMap; +using System.Diagnostics; namespace Sep.Git.Tfs.Commands { @@ -14,13 +15,11 @@ namespace Sep.Git.Tfs.Commands public class ResetRemote : GitTfsCommand { private readonly Globals globals; - private readonly TextWriter stdout; private bool ForceResetRemote; - public ResetRemote(Globals globals, TextWriter stdout) + public ResetRemote(Globals globals) { this.globals = globals; - this.stdout = stdout; } public virtual OptionSet OptionSet @@ -57,8 +56,8 @@ public int Run(string commitRef) globals.Repository.ResetRemote(targetCommit.Remote, targetCommit.GitCommit); - stdout.WriteLine("Remote 'tfs/" + targetCommit.Remote.Id + "' reset successfully.\n"); - stdout.WriteLine("Note: remember to use the '--force' option when doing the next 'fetch' to force git-tfs to fetch again the changesets!"); + Trace.TraceInformation("Remote 'tfs/" + targetCommit.Remote.Id + "' reset successfully.\n"); + Trace.TraceInformation("Note: remember to use the '--force' option when doing the next 'fetch' to force git-tfs to fetch again the changesets!"); return GitTfsExitCodes.OK; } } diff --git a/GitTfs/Commands/Shelve.cs b/GitTfs/Commands/Shelve.cs index 2e2775378..b29732c40 100644 --- a/GitTfs/Commands/Shelve.cs +++ b/GitTfs/Commands/Shelve.cs @@ -4,6 +4,7 @@ using Sep.Git.Tfs.Core; using Sep.Git.Tfs.Util; using StructureMap; +using System.Diagnostics; namespace Sep.Git.Tfs.Commands { @@ -12,7 +13,6 @@ namespace Sep.Git.Tfs.Commands [RequiresValidGitRepository] public class Shelve : GitTfsCommand { - private readonly TextWriter _stdout; private readonly CheckinOptions _checkinOptions; private readonly CheckinOptionsFactory _checkinOptionsFactory; private readonly TfsWriter _writer; @@ -20,12 +20,11 @@ public class Shelve : GitTfsCommand private bool EvaluateCheckinPolicies { get; set; } - public Shelve(TextWriter stdout, CheckinOptions checkinOptions, TfsWriter writer, Globals globals) + public Shelve(CheckinOptions checkinOptions, TfsWriter writer, Globals globals) { - _stdout = stdout; _globals = globals; _checkinOptions = checkinOptions; - _checkinOptionsFactory = new CheckinOptionsFactory(_stdout, _globals); + _checkinOptionsFactory = new CheckinOptionsFactory(_globals); _writer = writer; } @@ -54,7 +53,7 @@ public int Run(string shelvesetName, string refToShelve) { if (!_checkinOptions.Force && changeset.Remote.HasShelveset(shelvesetName)) { - _stdout.WriteLine("Shelveset \"" + shelvesetName + "\" already exists. Use -f to replace it."); + Trace.TraceInformation("Shelveset \"" + shelvesetName + "\" already exists. Use -f to replace it."); return GitTfsExitCodes.ForceRequired; } diff --git a/GitTfs/Commands/ShelveList.cs b/GitTfs/Commands/ShelveList.cs index e0b39fd33..969dc5199 100644 --- a/GitTfs/Commands/ShelveList.cs +++ b/GitTfs/Commands/ShelveList.cs @@ -14,7 +14,6 @@ namespace Sep.Git.Tfs.Commands [RequiresValidGitRepository] public class ShelveList : GitTfsCommand { - private readonly TextWriter _stdout; private readonly Globals _globals; public string SortBy { get; set; } @@ -37,9 +36,8 @@ public OptionSet OptionSet } } - public ShelveList(TextWriter stdout, Globals globals) + public ShelveList(Globals globals) { - _stdout = stdout; _globals = globals; } diff --git a/GitTfs/Commands/Subtree.cs b/GitTfs/Commands/Subtree.cs index 685771056..ef520b8ba 100644 --- a/GitTfs/Commands/Subtree.cs +++ b/GitTfs/Commands/Subtree.cs @@ -7,6 +7,7 @@ using NDesk.Options; using Sep.Git.Tfs.Core; using StructureMap; +using System.Diagnostics; namespace Sep.Git.Tfs.Commands { @@ -15,8 +16,6 @@ namespace Sep.Git.Tfs.Commands [RequiresValidGitRepository] public class Subtree : GitTfsCommand { - - private readonly TextWriter _stdout; private readonly Fetch _fetch; private readonly QuickFetch _quickFetch; private readonly Globals _globals; @@ -42,9 +41,8 @@ public OptionSet OptionSet } } - public Subtree(TextWriter stdout, Fetch fetch, QuickFetch quickFetch, Globals globals, RemoteOptions remoteOptions) + public Subtree(Fetch fetch, QuickFetch quickFetch, Globals globals, RemoteOptions remoteOptions) { - this._stdout = stdout; this._fetch = fetch; this._quickFetch = quickFetch; this._globals = globals; @@ -54,11 +52,11 @@ public Subtree(TextWriter stdout, Fetch fetch, QuickFetch quickFetch, Globals gl public int Run(IList args) { string command = args.FirstOrDefault() ?? ""; - _stdout.WriteLine("executing subtree " + command); + Trace.TraceInformation("executing subtree " + command); if (string.IsNullOrEmpty(Prefix)) { - _stdout.WriteLine("Prefix must be specified, use -p or -prefix"); + Trace.TraceInformation("Prefix must be specified, use -p or -prefix"); return GitTfsExitCodes.InvalidArguments; } @@ -74,7 +72,7 @@ public int Run(IList args) return DoSplit(); default: - _stdout.WriteLine("Expected one of [add, pull, split]"); + Trace.TraceInformation("Expected one of [add, pull, split]"); return GitTfsExitCodes.InvalidArguments; } } @@ -83,7 +81,7 @@ public int DoAdd(string tfsUrl, string tfsRepositoryPath) { if (File.Exists(Prefix) || Directory.Exists(Prefix)) { - _stdout.WriteLine(string.Format("Directory {0} already exists", Prefix)); + Trace.TraceInformation(string.Format("Directory {0} already exists", Prefix)); return GitTfsExitCodes.InvalidArguments; } @@ -118,12 +116,12 @@ public int DoAdd(string tfsUrl, string tfsRepositoryPath) Repository = null, RemoteOptions = _remoteOptions }); - _stdout.WriteLine("-> new owning remote " + owner.Id); + Trace.TraceInformation("-> new owning remote " + owner.Id); } else { ownerId = owner.Id; - _stdout.WriteLine("Attaching subtree to owning remote " + owner.Id); + Trace.TraceInformation("Attaching subtree to owning remote " + owner.Id); } @@ -139,7 +137,7 @@ public int DoAdd(string tfsUrl, string tfsRepositoryPath) RemoteOptions = _remoteOptions, }); - _stdout.WriteLine("-> new remote " + remote.Id); + Trace.TraceInformation("-> new remote " + remote.Id); fetch.BranchStrategy = BranchStrategy.None; diff --git a/GitTfs/Commands/Unshelve.cs b/GitTfs/Commands/Unshelve.cs index 89d735dee..d8405e287 100644 --- a/GitTfs/Commands/Unshelve.cs +++ b/GitTfs/Commands/Unshelve.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.ComponentModel; using System.Diagnostics; using System.IO; @@ -15,12 +15,10 @@ namespace Sep.Git.Tfs.Commands public class Unshelve : GitTfsCommand { private readonly Globals _globals; - private readonly TextWriter _stdout; - public Unshelve(Globals globals, TextWriter stdout) + public Unshelve(Globals globals) { _globals = globals; - _stdout = stdout; TfsBranch = null; } @@ -51,7 +49,7 @@ public int Run(string shelvesetName, string destinationBranch) var remote = _globals.Repository.ReadTfsRemote(TfsBranch); remote.Unshelve(Owner, shelvesetName, destinationBranch, BuildErrorHandler(), Force); - _stdout.WriteLine("Created branch " + destinationBranch + " from shelveset \"" + shelvesetName + "\"."); + Trace.TraceInformation("Created branch " + destinationBranch + " from shelveset \"" + shelvesetName + "\"."); return GitTfsExitCodes.OK; } @@ -61,7 +59,7 @@ private Action BuildErrorHandler() { return (e) => { - _stdout.WriteLine("WARNING: unshelve: " + e.Message); + Trace.TraceWarning("WARNING: unshelve: " + e.Message); Trace.WriteLine(e); }; } diff --git a/GitTfs/Commands/Verify.cs b/GitTfs/Commands/Verify.cs index d683998f3..cceaea780 100644 --- a/GitTfs/Commands/Verify.cs +++ b/GitTfs/Commands/Verify.cs @@ -8,6 +8,7 @@ using Sep.Git.Tfs.Core.TfsInterop; using StructureMap; using System.ComponentModel; +using System.Diagnostics; namespace Sep.Git.Tfs.Commands { @@ -17,15 +18,13 @@ namespace Sep.Git.Tfs.Commands public class Verify : GitTfsCommand { private readonly Help _helper; - private readonly TextWriter _stdout; private readonly Globals _globals; private readonly TreeVerifier _verifier; - public Verify(Globals globals, TreeVerifier verifier, TextWriter stdout, Help helper) + public Verify(Globals globals, TreeVerifier verifier, Help helper) { _globals = globals; _verifier = verifier; - _stdout = stdout; _helper = helper; } @@ -52,7 +51,7 @@ public int Run() int foundDiff = GitTfsExitCodes.OK; foreach (var remote in _globals.Repository.ReadAllTfsRemotes()) { - _stdout.WriteLine("Verifying remote '{0}' => '{1}' ...", remote.Id, remote.TfsRepositoryPath); + Trace.TraceInformation("Verifying remote '{0}' => '{1}' ...", remote.Id, remote.TfsRepositoryPath); foundDiff = Math.Max(foundDiff, RunFromCommitish(remote.RemoteRef)); } return foundDiff; @@ -86,18 +85,16 @@ private int RunFromCommitish(string commitish) public class TreeVerifier { - private readonly TextWriter _stdout; private readonly ITfsHelper _tfs; - public TreeVerifier(TextWriter stdout, ITfsHelper tfs) + public TreeVerifier(ITfsHelper tfs) { - _stdout = stdout; _tfs = tfs; } public int Verify(TfsChangesetInfo changeset, bool ignorePathCaseMismatch) { - _stdout.WriteLine("Comparing TFS changeset " + changeset.ChangesetId + " to git commit " + changeset.GitCommit); + Trace.TraceInformation("Comparing TFS changeset " + changeset.ChangesetId + " to git commit " + changeset.GitCommit); var tfsTree = changeset.Remote.GetChangeset(changeset.ChangesetId).GetTree().ToDictionary(entry => entry.FullName.ToLowerInvariant().Replace("/",@"\")); var gitTree = changeset.Remote.Repository.GetCommit(changeset.GitCommit).GetTree().ToDictionary(entry => entry.Entry.Path.ToLowerInvariant()); @@ -118,18 +115,18 @@ public int Verify(TfsChangesetInfo changeset, bool ignorePathCaseMismatch) } else { - _stdout.WriteLine("Only in TFS: " + tfsTree[file].FullName); + Trace.TraceInformation("Only in TFS: " + tfsTree[file].FullName); foundDiff = Math.Max(foundDiff, GitTfsExitCodes.VerifyFileMissing); } } else { - _stdout.WriteLine("Only in git: " + gitTree[file].FullName); + Trace.TraceInformation("Only in git: " + gitTree[file].FullName); foundDiff = Math.Max(foundDiff, GitTfsExitCodes.VerifyFileMissing); } } if(foundDiff == GitTfsExitCodes.OK) - _stdout.WriteLine("No differences!"); + Trace.TraceInformation("No differences!"); return foundDiff; } @@ -138,14 +135,14 @@ private bool Compare(TfsTreeEntry tfsTreeEntry, GitTreeEntry gitTreeEntry, bool var different = false; if (!ignorePathCaseMismatch && tfsTreeEntry.FullName.Replace("/", @"\") != gitTreeEntry.FullName) { - _stdout.WriteLine("Name case mismatch:"); - _stdout.WriteLine(" TFS: " + tfsTreeEntry.FullName); - _stdout.WriteLine(" git: " + gitTreeEntry.FullName); + Trace.TraceInformation("Name case mismatch:"); + Trace.TraceInformation(" TFS: " + tfsTreeEntry.FullName); + Trace.TraceInformation(" git: " + gitTreeEntry.FullName); different = true; } if(Hash(tfsTreeEntry) != Hash(gitTreeEntry)) { - _stdout.WriteLine(gitTreeEntry.FullName + " differs."); + Trace.TraceInformation(gitTreeEntry.FullName + " differs."); different = true; } return different; diff --git a/GitTfs/Commands/Version.cs b/GitTfs/Commands/Version.cs index 9c77bf0f3..e5bd44c43 100644 --- a/GitTfs/Commands/Version.cs +++ b/GitTfs/Commands/Version.cs @@ -4,6 +4,7 @@ using NDesk.Options; using StructureMap; using Sep.Git.Tfs.Core; +using System.Diagnostics; namespace Sep.Git.Tfs.Commands { @@ -12,7 +13,6 @@ namespace Sep.Git.Tfs.Commands public class Version : GitTfsCommand { private Globals globals; - TextWriter stdout; IGitTfsVersionProvider versionProvider; /// @@ -20,10 +20,9 @@ public class Version : GitTfsCommand /// /// /// - public Version(Globals globals, TextWriter stdout, IGitTfsVersionProvider versionProvider) + public Version(Globals globals, IGitTfsVersionProvider versionProvider) { this.globals = globals; - this.stdout = stdout; this.versionProvider = versionProvider; this.OptionSet = globals.OptionSet; @@ -31,10 +30,10 @@ public Version(Globals globals, TextWriter stdout, IGitTfsVersionProvider versio public int Run() { - stdout.WriteLine(versionProvider.GetVersionString()); - stdout.WriteLine(versionProvider.GetPathToGitTfsExecutable()); + Trace.TraceInformation(versionProvider.GetVersionString()); + Trace.TraceInformation(versionProvider.GetPathToGitTfsExecutable()); - stdout.WriteLine(GitTfsConstants.MessageForceVersion); + Trace.TraceInformation(GitTfsConstants.MessageForceVersion); return GitTfsExitCodes.OK; } diff --git a/GitTfs/Core/Bootstrapper.cs b/GitTfs/Core/Bootstrapper.cs index 13d37ca1a..58d706b0f 100644 --- a/GitTfs/Core/Bootstrapper.cs +++ b/GitTfs/Core/Bootstrapper.cs @@ -1,18 +1,17 @@ using System.IO; using Sep.Git.Tfs.Commands; // ToGitRefName() and RemoteOptions +using System.Diagnostics; namespace Sep.Git.Tfs.Core { public class Bootstrapper { readonly Globals _globals; - readonly TextWriter _stdout; readonly RemoteOptions _remoteOptions; - public Bootstrapper(Globals globals, TextWriter stdout, RemoteOptions remoteOptions) + public Bootstrapper(Globals globals, RemoteOptions remoteOptions) { _globals = globals; - _stdout = stdout; _remoteOptions = remoteOptions; } @@ -30,7 +29,7 @@ public IGitTfsRemote CreateRemote(TfsChangesetInfo changeset) RemoteOptions = _remoteOptions, }, string.Empty); remote.UpdateTfsHead(changeset.GitCommit, changeset.ChangesetId); - _stdout.WriteLine("-> new remote '" + remote.Id + "'"); + Trace.TraceInformation("-> new remote '" + remote.Id + "'"); } else { @@ -39,11 +38,11 @@ public IGitTfsRemote CreateRemote(TfsChangesetInfo changeset) { int oldChangeset = changeset.Remote.MaxChangesetId; _globals.Repository.MoveTfsRefForwardIfNeeded(changeset.Remote); - _stdout.WriteLine("-> existing remote {0} (updated from changeset {1})", changeset.Remote.Id, oldChangeset); + Trace.TraceInformation("-> existing remote {0} (updated from changeset {1})", changeset.Remote.Id, oldChangeset); } else { - _stdout.WriteLine("-> existing remote {0} (up to date)", changeset.Remote.Id); + Trace.TraceInformation("-> existing remote {0} (up to date)", changeset.Remote.Id); } } return remote; @@ -54,7 +53,7 @@ private string GetRemoteId(TfsChangesetInfo changeset) { if (IsAvailable(GitTfsConstants.DefaultRepositoryId)) { - _stdout.WriteLine("info: '" + changeset.Remote.TfsRepositoryPath + "' will be bootstraped as your main remote..."); + Trace.TraceInformation("info: '" + changeset.Remote.TfsRepositoryPath + "' will be bootstraped as your main remote..."); return GitTfsConstants.DefaultRepositoryId; } diff --git a/GitTfs/Core/GitHelpers.cs b/GitTfs/Core/GitHelpers.cs index 818089295..7aefe8832 100644 --- a/GitTfs/Core/GitHelpers.cs +++ b/GitTfs/Core/GitHelpers.cs @@ -9,7 +9,6 @@ namespace Sep.Git.Tfs.Core { public class GitHelpers : IGitHelpers { - protected readonly TextWriter realStdout; private readonly IContainer _container; /// @@ -18,9 +17,8 @@ public class GitHelpers : IGitHelpers /// private static Encoding _encoding = new UTF8Encoding(false, true); - public GitHelpers(TextWriter stdout, IContainer container) + public GitHelpers(IContainer container) { - realStdout = stdout; _container = container; } @@ -49,7 +47,7 @@ public string CommandOneline(params string[] command) /// public void CommandNoisy(params string[] command) { - CommandOutputPipe(stdout => realStdout.Write(stdout.ReadToEnd()), command); + CommandOutputPipe(stdout => Trace.TraceInformation(stdout.ReadToEnd()), command); } /// diff --git a/GitTfs/Core/GitRepository.cs b/GitTfs/Core/GitRepository.cs index 00bc5f41f..67a06f779 100644 --- a/GitTfs/Core/GitRepository.cs +++ b/GitTfs/Core/GitRepository.cs @@ -19,8 +19,8 @@ public class GitRepository : GitHelpers, IGitRepository private Repository _repository; private RemoteConfigConverter _remoteConfigReader; - public GitRepository(TextWriter stdout, string gitDir, IContainer container, Globals globals, RemoteConfigConverter remoteConfigReader) - : base(stdout, container) + public GitRepository(string gitDir, IContainer container, Globals globals, RemoteConfigConverter remoteConfigReader) + : base(container) { _container = container; _globals = globals; @@ -687,7 +687,7 @@ public void GarbageCollect(bool auto, string additionalMessage) catch (Exception e) { Trace.WriteLine(e); - realStdout.WriteLine("Warning: `git gc` failed! " + additionalMessage); + Trace.TraceWarning("Warning: `git gc` failed! " + additionalMessage); } } diff --git a/GitTfs/Core/GitTfsRemote.cs b/GitTfs/Core/GitTfsRemote.cs index fa9c11ecc..47df0837b 100644 --- a/GitTfs/Core/GitTfsRemote.cs +++ b/GitTfs/Core/GitTfsRemote.cs @@ -16,7 +16,6 @@ public class GitTfsRemote : IGitTfsRemote private static readonly Regex isInDotGit = new Regex("(?:^|/)\\.git(?:/|$)", RegexOptions.Compiled); private readonly Globals globals; - private readonly TextWriter stdout; private readonly RemoteOptions remoteOptions; private readonly ConfigProperties properties; private int? maxChangesetId; @@ -25,11 +24,10 @@ public class GitTfsRemote : IGitTfsRemote public RemoteInfo RemoteInfo { get; private set; } public GitTfsRemote(RemoteInfo info, IGitRepository repository, RemoteOptions remoteOptions, Globals globals, - ITfsHelper tfsHelper, TextWriter stdout, ConfigProperties properties) + ITfsHelper tfsHelper, ConfigProperties properties) { this.remoteOptions = remoteOptions; this.globals = globals; - this.stdout = stdout; this.properties = properties; Tfs = tfsHelper; Repository = repository; @@ -394,7 +392,7 @@ private bool ProcessMergeChangeset(ITfsChangeset changeset, bool stopOnFailMerge { if (!Tfs.CanGetBranchInformation) { - stdout.WriteLine("info: this changeset " + changeset.Summary.ChangesetId + + Trace.TraceInformation("info: this changeset " + changeset.Summary.ChangesetId + " is a merge changeset. But was not treated as is because this version of TFS can't manage branches..."); } else if (!IsIgnoringBranches()) @@ -406,7 +404,7 @@ private bool ProcessMergeChangeset(ITfsChangeset changeset, bool stopOnFailMerge { return false; } - stdout.WriteLine("warning: this changeset " + changeset.Summary.ChangesetId + + Trace.TraceInformation("warning: this changeset " + changeset.Summary.ChangesetId + " is a merge changeset. But git-tfs is unable to determine the parent changeset."); return true; } @@ -426,14 +424,14 @@ private bool ProcessMergeChangeset(ITfsChangeset changeset, bool stopOnFailMerge if (stopOnFailMergeCommit) return false; - stdout.WriteLine("warning: this changeset " + changeset.Summary.ChangesetId + + Trace.TraceInformation("warning: this changeset " + changeset.Summary.ChangesetId + " is a merge changeset. But git-tfs failed to find and fetch the parent changeset " + parentChangesetId + ". Parent changeset will be ignored..."); } } else { - stdout.WriteLine("info: this changeset " + changeset.Summary.ChangesetId + + Trace.TraceInformation("info: this changeset " + changeset.Summary.ChangesetId + " is a merge changeset. But was not treated as is because of your git setting..."); changeset.OmittedParentBranch = ";C" + changeset.Summary.ChangesetId; } @@ -447,12 +445,12 @@ public bool IsIgnoringBranches() if (value != null && bool.TryParse(value, out isIgnoringBranches)) return isIgnoringBranches; - stdout.WriteLine("warning: no value found for branch management setting '" + GitTfsConstants.IgnoreBranches + + Trace.TraceInformation("warning: no value found for branch management setting '" + GitTfsConstants.IgnoreBranches + "'..."); var isIgnoringBranchesDetected = Repository.ReadAllTfsRemotes().Count() < 2; - stdout.WriteLine("=> Branch support " + (isIgnoringBranchesDetected ? "disabled!" : "enabled!")); + Trace.TraceInformation("=> Branch support " + (isIgnoringBranchesDetected ? "disabled!" : "enabled!")); if(isIgnoringBranchesDetected) - stdout.WriteLine(" if you want to enable branch support, use the command:" + Environment.NewLine + Trace.TraceInformation(" if you want to enable branch support, use the command:" + Environment.NewLine + " git config --local " + GitTfsConstants.IgnoreBranches + " false"); globals.Repository.SetConfig(GitTfsConstants.IgnoreBranches, isIgnoringBranchesDetected.ToString()); return isIgnoringBranchesDetected; @@ -555,7 +553,7 @@ private string FindRemoteAndFetch(int parentChangesetId, bool stopOnFailMergeCom if (tfsRemote != null && string.Compare(tfsRemote.TfsRepositoryPath, TfsRepositoryPath, StringComparison.InvariantCultureIgnoreCase) != 0) { - stdout.WriteLine("\tFetching from dependent TFS remote '{0}'...", tfsRemote.Id); + Trace.TraceInformation("\tFetching from dependent TFS remote '{0}'...", tfsRemote.Id); try { var fetchResult = ((GitTfsRemote) tfsRemote).FetchWithMerge(-1, stopOnFailMergeCommit, parentChangesetId, renameResult); @@ -606,13 +604,13 @@ private IGitTfsRemote FindOrInitTfsRemoteOfChangeset(int parentChangesetId, bool if (mergeChangeset && tfsBranch != null && Repository.GetConfig(GitTfsConstants.IgnoreNotInitBranches) == true.ToString()) { - stdout.WriteLine("warning: skip not initialized branch for path " + tfsBranch.Path); + Trace.TraceInformation("warning: skip not initialized branch for path " + tfsBranch.Path); tfsRemote = null; omittedParentBranch = tfsBranch.Path + ";C" + parentChangesetId; } else if (tfsBranch == null) { - stdout.WriteLine("error: branch not found. Verify that all the folders have been converted to branches (or something else :().\n\tpath {0}", tfsPath); + Trace.TraceInformation("error: branch not found. Verify that all the folders have been converted to branches (or something else :().\n\tpath {0}", tfsPath); tfsRemote = null; omittedParentBranch = ";C" + parentChangesetId; } @@ -642,8 +640,8 @@ private IGitTfsRemote InitTfsRemoteOfChangeset(IBranchObject tfsBranch, int pare remote = InitBranch(this.remoteOptions, tfsBranch.Path, rootChangesetId, true); if (remote == null) { - stdout.WriteLine("warning: root commit not found corresponding to changeset " + rootChangesetId); - stdout.WriteLine("=> continuing anyway by creating a branch without parent..."); + Trace.TraceInformation("warning: root commit not found corresponding to changeset " + rootChangesetId); + Trace.TraceInformation("=> continuing anyway by creating a branch without parent..."); return InitTfsBranch(this.remoteOptions, tfsBranch.Path); } @@ -735,7 +733,7 @@ public void UpdateTfsHead(string commitHash, int changesetId) private void LogCurrentMapping() { - stdout.WriteLine("C" + MaxChangesetId + " = " + MaxCommitHash); + Trace.TraceInformation("C" + MaxChangesetId + " = " + MaxCommitHash); } private string TagPrefix @@ -828,7 +826,7 @@ public void Unshelve(string shelvesetOwner, string shelvesetName, string destina "Try applying the shelveset on the currently checkouted commit using the '--force' option" } ); - stdout.WriteLine("warning: Parent changeset C" + parentId + " not found." + Trace.TraceInformation("warning: Parent changeset C" + parentId + " not found." + " Trying to apply the shelveset on the current commit..."); rootCommit = Repository.GetCurrentCommit(); } @@ -939,7 +937,7 @@ private string ExtractGitBranchNameFromTfsRepositoryPath(string tfsRepositoryPat var includeTeamProjectName = !Repository.IsInSameTeamProjectAsDefaultRepository(tfsRepositoryPath); var gitBranchName = tfsRepositoryPath.ToGitBranchNameFromTfsRepositoryPath(includeTeamProjectName); gitBranchName = Repository.AssertValidBranchName(gitBranchName); - stdout.WriteLine("The name of the local branch will be : " + gitBranchName); + Trace.TraceInformation("The name of the local branch will be : " + gitBranchName); return gitBranchName; } diff --git a/GitTfs/Core/TfsChangeset.cs b/GitTfs/Core/TfsChangeset.cs index 758fe0c7d..600ae32bd 100644 --- a/GitTfs/Core/TfsChangeset.cs +++ b/GitTfs/Core/TfsChangeset.cs @@ -12,16 +12,14 @@ public class TfsChangeset : ITfsChangeset { private readonly ITfsHelper _tfs; private readonly IChangeset _changeset; - private readonly TextWriter _stdout; private readonly AuthorsFile _authors; public TfsChangesetInfo Summary { get; set; } public int BaseChangesetId { get; set; } - public TfsChangeset(ITfsHelper tfs, IChangeset changeset, TextWriter stdout, AuthorsFile authors) + public TfsChangeset(ITfsHelper tfs, IChangeset changeset, AuthorsFile authors) { _tfs = tfs; _changeset = changeset; - _stdout = stdout; _authors = authors; BaseChangesetId = _changeset.Changes.Max(c => c.Item.ChangesetId) - 1; } @@ -73,7 +71,7 @@ private void Update(ApplicableChange change, IGitTreeModifier treeBuilder, ITfsW } else { - _stdout.WriteLine("Cannot checkout file '{0}' from TFS. Skip it", change.GitPath); + Trace.TraceInformation("Cannot checkout file '{0}' from TFS. Skip it", change.GitPath); } } @@ -131,7 +129,7 @@ public LogEntry CopyTree(IGitTreeModifier treeBuilder, ITfsWorkspace workspace) itemsCopied++; if (DateTime.Now - startTime > TimeSpan.FromSeconds(30)) { - _stdout.WriteLine("{0} objects created...", itemsCopied); + Trace.TraceInformation("{0} objects created...", itemsCopied); startTime = DateTime.Now; } } diff --git a/GitTfs/Core/TfsWorkspace.cs b/GitTfs/Core/TfsWorkspace.cs index d7d933242..12b778603 100644 --- a/GitTfs/Core/TfsWorkspace.cs +++ b/GitTfs/Core/TfsWorkspace.cs @@ -5,6 +5,7 @@ using System.Linq; using Sep.Git.Tfs.Commands; using Sep.Git.Tfs.Core.TfsInterop; +using System.Diagnostics; namespace Sep.Git.Tfs.Core { @@ -12,7 +13,6 @@ public class TfsWorkspace : ITfsWorkspace { private readonly IWorkspace _workspace; private readonly string _localDirectory; - private readonly TextWriter _stdout; private readonly TfsChangesetInfo _contextVersion; private readonly CheckinOptions _checkinOptions; private readonly ITfsHelper _tfsHelper; @@ -20,7 +20,7 @@ public class TfsWorkspace : ITfsWorkspace public IGitTfsRemote Remote { get; private set; } - public TfsWorkspace(IWorkspace workspace, string localDirectory, TextWriter stdout, TfsChangesetInfo contextVersion, IGitTfsRemote remote, CheckinOptions checkinOptions, ITfsHelper tfsHelper, CheckinPolicyEvaluator policyEvaluator) + public TfsWorkspace(IWorkspace workspace, string localDirectory, TfsChangesetInfo contextVersion, IGitTfsRemote remote, CheckinOptions checkinOptions, ITfsHelper tfsHelper, CheckinPolicyEvaluator policyEvaluator) { _workspace = workspace; _policyEvaluator = policyEvaluator; @@ -28,7 +28,6 @@ public TfsWorkspace(IWorkspace workspace, string localDirectory, TextWriter stdo _checkinOptions = checkinOptions; _tfsHelper = tfsHelper; _localDirectory = remote.Repository.IsBare ? Path.GetFullPath(localDirectory) : localDirectory; - _stdout = stdout; this.Remote = remote; } @@ -47,7 +46,7 @@ public void Shelve(string shelvesetName, bool evaluateCheckinPolicies, CheckinOp { foreach (var message in _policyEvaluator.EvaluateCheckin(_workspace, pendingChanges, shelveset.Comment, null, shelveset.WorkItemInfo).Messages) { - _stdout.WriteLine("[Checkin Policy] " + message); + Trace.TraceWarning("[Checkin Policy] " + message); } } _workspace.Shelve(shelveset, pendingChanges, _checkinOptions.Force ? TfsShelvingOptions.Replace : TfsShelvingOptions.None); @@ -98,11 +97,11 @@ public int Checkin(CheckinOptions options, Func generateCheckinComment = { if (options.Force && string.IsNullOrWhiteSpace(options.OverrideReason) == false) { - _stdout.WriteLine("[OVERRIDDEN] " + message); + Trace.TraceWarning("[OVERRIDDEN] " + message); } else { - _stdout.WriteLine("[ERROR] " + message); + Trace.TraceError("[ERROR] " + message); } } if (!options.Force) @@ -136,7 +135,7 @@ public int Checkin(CheckinOptions options, Func generateCheckinComment = private int LaunchGatedCheckinBuild(ReadOnlyCollection> affectedBuildDefinitions, string shelvesetName, string checkInTicket) { - _stdout.WriteLine("Due to a gated check-in, a shelveset '" + shelvesetName + "' containing your changes has been created and need to be built before it can be committed."); + Trace.TraceInformation("Due to a gated check-in, a shelveset '" + shelvesetName + "' containing your changes has been created and need to be built before it can be committed."); KeyValuePair buildDefinition; if (affectedBuildDefinitions.Count == 1) { @@ -147,12 +146,12 @@ private int LaunchGatedCheckinBuild(ReadOnlyCollection int choice; do { - _stdout.WriteLine("Build definitions that can be used:"); + Trace.TraceInformation("Build definitions that can be used:"); for (int i = 0; i < affectedBuildDefinitions.Count; i++) { - _stdout.WriteLine((i + 1) + ": " + affectedBuildDefinitions[i].Key); + Trace.TraceInformation((i + 1) + ": " + affectedBuildDefinitions[i].Key); } - _stdout.WriteLine("Please choose the build definition to trigger?"); + Trace.TraceInformation("Please choose the build definition to trigger?"); } while (!int.TryParse(Console.ReadLine(), out choice) || choice <= 0 || choice > affectedBuildDefinitions.Count); buildDefinition = affectedBuildDefinitions.ElementAt(choice - 1); } @@ -173,7 +172,7 @@ public string GetLocalPath(string path) public void Add(string path) { - _stdout.WriteLine(" add " + path); + Trace.TraceInformation(" add " + path); var added = _workspace.PendAdd(GetLocalPath(path)); if (added != 1) throw new Exception("One item should have been added, but actually added " + added + " items."); } @@ -181,18 +180,18 @@ public void Add(string path) public void Edit(string path) { var localPath = GetLocalPath(path); - _stdout.WriteLine(" edit " + localPath); + Trace.TraceInformation(" edit " + localPath); GetFromTfs(localPath); var edited = _workspace.PendEdit(localPath); if (edited != 1) { if (_checkinOptions.IgnoreMissingItems) { - _stdout.WriteLine("Warning: One item should have been edited, but actually edited " + edited + ". Ignoring item."); + Trace.TraceWarning("Warning: One item should have been edited, but actually edited " + edited + ". Ignoring item."); } else if (edited == 0 && _checkinOptions.AddMissingItems) { - _stdout.WriteLine("Warning: One item should have been edited, but was not found. Adding the file instead."); + Trace.TraceWarning("Warning: One item should have been edited, but was not found. Adding the file instead."); Add(path); } else @@ -205,7 +204,7 @@ public void Edit(string path) public void Delete(string path) { path = GetLocalPath(path); - _stdout.WriteLine(" delete " + path); + Trace.TraceInformation(" delete " + path); GetFromTfs(path); var deleted = _workspace.PendDelete(path); if (deleted != 1) throw new Exception("One item should have been deleted, but actually deleted " + deleted + " items."); @@ -213,7 +212,7 @@ public void Delete(string path) public void Rename(string pathFrom, string pathTo, string score) { - _stdout.WriteLine(" rename " + pathFrom + " to " + pathTo + " (score: " + score + ")"); + Trace.TraceInformation(" rename " + pathFrom + " to " + pathTo + " (score: " + score + ")"); GetFromTfs(GetLocalPath(pathFrom)); var result = _workspace.PendRename(GetLocalPath(pathFrom), GetLocalPath(pathTo)); if (result != 1) throw new ApplicationException("Unable to rename item from " + pathFrom + " to " + pathTo); diff --git a/GitTfs/Core/TfsWriter.cs b/GitTfs/Core/TfsWriter.cs index b312d9697..3d72742b6 100644 --- a/GitTfs/Core/TfsWriter.cs +++ b/GitTfs/Core/TfsWriter.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Text; @@ -8,12 +9,10 @@ namespace Sep.Git.Tfs.Core { public class TfsWriter { - private readonly TextWriter _stdout; private readonly Globals _globals; - public TfsWriter(TextWriter stdout, Globals globals) + public TfsWriter(Globals globals) { - _stdout = stdout; _globals = globals; } @@ -34,7 +33,7 @@ private int WriteWith(IEnumerable tfsParents, string refToWrit var changeset = tfsParents.First(); return write(changeset, refToWrite); case 0: - _stdout.WriteLine("No TFS parents found!"); + Trace.TraceError("No TFS parents found!"); return GitTfsExitCodes.InvalidArguments; default: if (tfsParents.Select(x => x.Remote.IsSubtree ? x.Remote.OwningRemoteId : x.Remote.Id).Distinct().Count() == 1) @@ -45,14 +44,14 @@ private int WriteWith(IEnumerable tfsParents, string refToWrit var lastChangeSet = tfsParents.OrderByDescending(x => x.ChangesetId).First(); if (lastChangeSet.Remote.IsSubtree) lastChangeSet.Remote = _globals.Repository.ReadTfsRemote(lastChangeSet.Remote.OwningRemoteId); - _stdout.WriteLine(string.Format("Basing from parent '{0}:{1}', use -i to override", lastChangeSet.Remote.Id, lastChangeSet.ChangesetId)); + Trace.TraceInformation(string.Format("Basing from parent '{0}:{1}', use -i to override", lastChangeSet.Remote.Id, lastChangeSet.ChangesetId)); return write(lastChangeSet, refToWrite); } - _stdout.WriteLine("More than one parent found! Use -i to choose the correct parent from: "); + Trace.TraceWarning("More than one parent found! Use -i to choose the correct parent from: "); foreach (var parent in tfsParents) { - _stdout.WriteLine(" " + parent.Remote.Id); + Trace.TraceWarning(" " + parent.Remote.Id); } return GitTfsExitCodes.InvalidArguments; } diff --git a/GitTfs/GitTfs.cs b/GitTfs/GitTfs.cs index b2f463286..d2f7a0f5d 100644 --- a/GitTfs/GitTfs.cs +++ b/GitTfs/GitTfs.cs @@ -9,6 +9,8 @@ using Sep.Git.Tfs.Core; using Sep.Git.Tfs.Core.TfsInterop; using Sep.Git.Tfs.Util; +using NLog; +using NLog.Targets; namespace Sep.Git.Tfs { @@ -21,11 +23,10 @@ public class GitTfs private readonly IContainer _container; private readonly GitTfsCommandRunner _runner; private readonly Globals _globals; - private TextWriter _stdout; private Bootstrapper _bootstrapper; public GitTfs(ITfsHelper tfsHelper, GitTfsCommandFactory commandFactory, IHelpHelper help, IContainer container, - IGitTfsVersionProvider gitTfsVersionProvider, GitTfsCommandRunner runner, Globals globals, TextWriter stdout, Bootstrapper bootstrapper) + IGitTfsVersionProvider gitTfsVersionProvider, GitTfsCommandRunner runner, Globals globals, Bootstrapper bootstrapper) { this.tfsHelper = tfsHelper; this.commandFactory = commandFactory; @@ -34,7 +35,6 @@ public GitTfs(ITfsHelper tfsHelper, GitTfsCommandFactory commandFactory, IHelpHe _gitTfsVersionProvider = gitTfsVersionProvider; _runner = runner; _globals = globals; - _stdout = stdout; _bootstrapper = bootstrapper; } @@ -43,13 +43,25 @@ public int Run(IList args) InitializeGlobals(); _globals.CommandLineRun = "git tfs " + string.Join(" ", args); var command = ExtractCommand(args); - if(RequiresValidGitRepository(command)) AssertValidGitRepository(); var unparsedArgs = ParseOptions(command, args); + UpdateLoggerOnDebugging(); Trace.WriteLine("Command run:" + _globals.CommandLineRun); + if (RequiresValidGitRepository(command)) AssertValidGitRepository(); ParseAuthors(); return Main(command, unparsedArgs); } + private void UpdateLoggerOnDebugging() + { + if (_globals.DebugOutput) + { + var consoleRule = LogManager.Configuration.LoggingRules.First(); + consoleRule.EnableLoggingForLevel(LogLevel.Debug); + //consoleRule.DisableLoggingForLevel(LogLevel.Trace); + LogManager.ReconfigExistingLoggers(); + } + } + public int Main(GitTfsCommand command, IList unparsedArgs) { Trace.WriteLine(_gitTfsVersionProvider.GetVersionString()); @@ -59,8 +71,8 @@ public int Main(GitTfsCommand command, IList unparsedArgs) } else if(_globals.ShowVersion) { - _container.GetInstance().WriteLine(_gitTfsVersionProvider.GetVersionString()); - _container.GetInstance().WriteLine(GitTfsConstants.MessageForceVersion); + Trace.TraceInformation(_gitTfsVersionProvider.GetVersionString()); + Trace.TraceInformation(GitTfsConstants.MessageForceVersion); return GitTfsExitCodes.OK; } else @@ -89,11 +101,11 @@ private void ParseAuthors() } catch (Exception ex) { - Trace.WriteLine(ex); + Trace.WriteLine("Error when parsing author file:" + ex); if (!string.IsNullOrEmpty(_globals.AuthorsFilePath)) throw; - _stdout.WriteLine("warning: author file ignored due to a problem occuring when reading it :\n\t" + ex.Message); - _stdout.WriteLine(" Verify the file :" + Path.Combine(_globals.GitDir, AuthorsFile.GitTfsCachedAuthorsFileName)); + Trace.TraceWarning("warning: author file ignored due to a problem occuring when reading it :\n\t" + ex.Message); + Trace.TraceWarning(" Verify the file :" + Path.Combine(_globals.GitDir, AuthorsFile.GitTfsCachedAuthorsFileName)); } } @@ -116,7 +128,6 @@ public void InitializeGlobals() { _globals.GitDir = ".git"; } - _globals.Stdout = _stdout; _globals.Bootstrapper = _bootstrapper; } diff --git a/GitTfs/GitTfs.csproj b/GitTfs/GitTfs.csproj index b039da187..7e8e564d5 100644 --- a/GitTfs/GitTfs.csproj +++ b/GitTfs/GitTfs.csproj @@ -277,6 +277,14 @@ + + + + <__paket__LibGit2Sharp_props>net40\LibGit2Sharp + + + + - - - <__paket__LibGit2Sharp_props>net40\LibGit2Sharp - + + + + ..\packages\LibGit2Sharp\lib\net40\LibGit2Sharp.dll + True + True + + - - + - - ..\packages\LibGit2Sharp\lib\net40\LibGit2Sharp.dll + + ..\packages\NLog\lib\MonoAndroid10\NLog.dll + True + True + + + + + + + ..\packages\NLog\lib\net35\NLog.dll + True + True + + + + + + + ..\packages\NLog\lib\net40\NLog.dll + True + True + + + + + + + ..\packages\NLog\lib\net45\NLog.dll + True + True + + + + + + + ..\packages\NLog\lib\sl4\NLog.dll + True + True + + + + + + + ..\packages\NLog\lib\sl5\NLog.dll + True + True + + + + + + + ..\packages\NLog\lib\wp8\NLog.dll + True + True + + + + + + + ..\packages\NLog\lib\Xamarin.iOS10\NLog.dll True True @@ -219,7 +302,7 @@ - + ..\packages\xunit\lib\net20\xunit.dll @@ -230,7 +313,7 @@ - + ..\packages\xunit.extensions\lib\net20\xunit.extensions.dll @@ -240,12 +323,4 @@ - - - - <__paket__xunit_runner_visualstudio_props>net20\xunit.runner.visualstudio - - - - \ No newline at end of file diff --git a/GitTfsTest/Integration/BootstrapTests.cs b/GitTfsTest/Integration/BootstrapTests.cs index 6e35f7059..1bcd6b852 100644 --- a/GitTfsTest/Integration/BootstrapTests.cs +++ b/GitTfsTest/Integration/BootstrapTests.cs @@ -5,7 +5,7 @@ namespace Sep.Git.Tfs.Test.Integration { - public class BootstrapTests : IDisposable + public class BootstrapTests : BaseTest, IDisposable { IntegrationHelper h = new IntegrationHelper(); diff --git a/GitTfsTest/Integration/CloneTests.cs b/GitTfsTest/Integration/CloneTests.cs index 6c6febd1a..0089b8d20 100644 --- a/GitTfsTest/Integration/CloneTests.cs +++ b/GitTfsTest/Integration/CloneTests.cs @@ -9,7 +9,7 @@ namespace Sep.Git.Tfs.Test.Integration //NOTE: All timestamps in these tests must specify a time zone. If they don't, the local time zone will be used in the DateTime, // but the commit timestamp will use the ToUniversalTime() version of the DateTime. // This will cause the hashes to differ on computers in different time zones. - public class CloneTests : IDisposable + public class CloneTests : BaseTest, IDisposable { IntegrationHelper h; diff --git a/GitTfsTest/Integration/FetchTests.cs b/GitTfsTest/Integration/FetchTests.cs index 09cf321d8..533565be8 100644 --- a/GitTfsTest/Integration/FetchTests.cs +++ b/GitTfsTest/Integration/FetchTests.cs @@ -4,7 +4,7 @@ namespace Sep.Git.Tfs.Test.Integration { - public class FetchTests : IDisposable + public class FetchTests : BaseTest, IDisposable { private readonly IntegrationHelper integrationHelper; diff --git a/GitTfsTest/Integration/GitRepositoryTests.cs b/GitTfsTest/Integration/GitRepositoryTests.cs index bfa63f938..221f8b333 100644 --- a/GitTfsTest/Integration/GitRepositoryTests.cs +++ b/GitTfsTest/Integration/GitRepositoryTests.cs @@ -9,7 +9,7 @@ namespace Sep.Git.Tfs.Test.Integration { - public class GitRepositoryTests : IDisposable + public class GitRepositoryTests : BaseTest, IDisposable { IntegrationHelper h = new IntegrationHelper(); @@ -44,7 +44,7 @@ public void GetLastParentTfsCommits_WhenThereIsMoreThanTfsChangeset_ThenReturnTh using (var repo = h.Repository("repo")) { - var gitRepository = new GitRepository(new StringWriter(), repo.Info.WorkingDirectory, new Container(), null, new RemoteConfigConverter()); + var gitRepository = new GitRepository(repo.Info.WorkingDirectory, new Container(), null, new RemoteConfigConverter()); var changesets = gitRepository.GetLastParentTfsCommits("HEAD"); Assert.Equal(1, changesets.Count()); Assert.Equal(c3, changesets.First().GitCommit); @@ -76,7 +76,7 @@ public void GetLastParentTfsCommits_WhenTheMergeCommitIsNotFromTfs_ThenReturnThe using (var repo = h.Repository("repo")) { - var gitRepository = new GitRepository(new StringWriter(), repo.Info.WorkingDirectory, new Container(), null, new RemoteConfigConverter()); + var gitRepository = new GitRepository(repo.Info.WorkingDirectory, new Container(), null, new RemoteConfigConverter()); var changesets = gitRepository.GetLastParentTfsCommits("HEAD"); Assert.Equal(2, changesets.Count()); //C3 must be returned first because that's the parent commit of the master branch where the other branch is merged @@ -113,7 +113,7 @@ public void GetLastParentTfsCommits_WhenTheMergeCommitIsFromTfs_ThenReturnThisCo using (var repo = h.Repository("repo")) { - var gitRepository = new GitRepository(new StringWriter(), repo.Info.WorkingDirectory, new Container(), null, new RemoteConfigConverter()); + var gitRepository = new GitRepository(repo.Info.WorkingDirectory, new Container(), null, new RemoteConfigConverter()); var changesets = gitRepository.GetLastParentTfsCommits("HEAD"); Assert.Equal(1, changesets.Count()); Assert.Equal(c4, changesets.First().GitCommit); @@ -138,7 +138,7 @@ public void GetLastParentTfsCommits_WhenNoCommitFromTfs_ThenReturnNothing() using (var repo = h.Repository("repo")) { - var gitRepository = new GitRepository(new StringWriter(), repo.Info.WorkingDirectory, new Container(), null, new RemoteConfigConverter()); + var gitRepository = new GitRepository(repo.Info.WorkingDirectory, new Container(), null, new RemoteConfigConverter()); var changesets = gitRepository.GetLastParentTfsCommits("HEAD"); Assert.Equal(0, changesets.Count()); } @@ -181,7 +181,7 @@ public void FindParentCommits() using (var repo = h.Repository("repo")) { - var gitRepository = new GitRepository(new StringWriter(), repo.Info.WorkingDirectory, new Container(), null, new RemoteConfigConverter()); + var gitRepository = new GitRepository(repo.Info.WorkingDirectory, new Container(), null, new RemoteConfigConverter()); //string revList = gitRepository.CommandOneline("rev-list", "--parents", "--ancestry-path", "--first-parent", "--reverse", c1 + ".." + c4); var changesets = gitRepository.FindParentCommits(c5, c1); diff --git a/GitTfsTest/Integration/InitTests.cs b/GitTfsTest/Integration/InitTests.cs index 00587be16..02de8e738 100644 --- a/GitTfsTest/Integration/InitTests.cs +++ b/GitTfsTest/Integration/InitTests.cs @@ -3,7 +3,7 @@ namespace Sep.Git.Tfs.Test.Integration { - public class InitTests : IDisposable + public class InitTests : BaseTest, IDisposable { IntegrationHelper h; diff --git a/GitTfsTest/Integration/IntegrationHelper.cs b/GitTfsTest/Integration/IntegrationHelper.cs index be8f8f903..49ac12276 100644 --- a/GitTfsTest/Integration/IntegrationHelper.cs +++ b/GitTfsTest/Integration/IntegrationHelper.cs @@ -78,7 +78,7 @@ public T GetConfig(string repodir, string key) public void SetupGitRepo(string path, Action buildIt) { var fullPath = Path.Combine(Workdir, path); - System.Diagnostics.Trace.WriteLine("Repository path:" + fullPath); + Console.WriteLine("Repository path:" + fullPath); var repoPath = LibGit2Sharp.Repository.Init(fullPath); using (var repo = new Repository(repoPath)) buildIt(new RepoBuilder(repo)); diff --git a/GitTfsTest/Util/AuthorsFileUnitTest.cs b/GitTfsTest/Util/AuthorsFileUnitTest.cs index 5227f6129..3d08f0cec 100644 --- a/GitTfsTest/Util/AuthorsFileUnitTest.cs +++ b/GitTfsTest/Util/AuthorsFileUnitTest.cs @@ -9,7 +9,7 @@ namespace Sep.Git.Tfs.Test.Util { - public class AuthorsFileUnitTest + public class AuthorsFileUnitTest : BaseTest { [Fact] public void AuthorsFileEmptyFile() diff --git a/GitTfsTest/Util/BouncerTest.cs b/GitTfsTest/Util/BouncerTest.cs index d71481423..bfbcfceab 100644 --- a/GitTfsTest/Util/BouncerTest.cs +++ b/GitTfsTest/Util/BouncerTest.cs @@ -4,7 +4,7 @@ namespace Sep.Git.Tfs.Test.Util { - public class BouncerTest + public class BouncerTest : BaseTest { Bouncer bouncer = new Bouncer(); diff --git a/GitTfsTest/Util/CommitSpecificCheckinOptionsFactoryTests.cs b/GitTfsTest/Util/CommitSpecificCheckinOptionsFactoryTests.cs index b9b44432c..1968981a5 100644 --- a/GitTfsTest/Util/CommitSpecificCheckinOptionsFactoryTests.cs +++ b/GitTfsTest/Util/CommitSpecificCheckinOptionsFactoryTests.cs @@ -10,7 +10,7 @@ namespace Sep.Git.Tfs.Test.Util { - public class CommitSpecificCheckinOptionsFactoryTests + public class CommitSpecificCheckinOptionsFactoryTests : BaseTest { private RhinoAutoMocker mocks; @@ -28,7 +28,7 @@ private CheckinOptionsFactory GetCheckinOptionsFactory(string workItemRegex = nu gitRepository.Stub(r => r.GitDir).Return("."); gitRepository.Stub(r => r.GetConfig(GitTfsConstants.WorkItemAssociateRegexConfigKey)).Return(workItemRegex); - return new CheckinOptionsFactory(new StringWriter(), mocks.Get()); + return new CheckinOptionsFactory(mocks.Get()); } [Fact] diff --git a/GitTfsTest/Util/GitTfsCommandRunnerTests.cs b/GitTfsTest/Util/GitTfsCommandRunnerTests.cs index ccfb31e75..ed84837b8 100644 --- a/GitTfsTest/Util/GitTfsCommandRunnerTests.cs +++ b/GitTfsTest/Util/GitTfsCommandRunnerTests.cs @@ -10,7 +10,7 @@ namespace Sep.Git.Tfs.Test.Util { - public class GitTfsCommandRunnerTests + public class GitTfsCommandRunnerTests : BaseTest { #region Base implementation of GitTfsCommand, for tests @@ -42,7 +42,6 @@ public static Invocation Split(params string[]args) public GitTfsCommandRunnerTests() { _mocks = new RhinoAutoMocker(MockMode.AAA); - _mocks.Inject(new StringWriter()); } IList Args(params string[] args) diff --git a/GitTfsTest/Util/ShelveSpecificCheckinOptionsFactoryTests.cs b/GitTfsTest/Util/ShelveSpecificCheckinOptionsFactoryTests.cs index 27d2bf689..9fba26946 100644 --- a/GitTfsTest/Util/ShelveSpecificCheckinOptionsFactoryTests.cs +++ b/GitTfsTest/Util/ShelveSpecificCheckinOptionsFactoryTests.cs @@ -41,7 +41,7 @@ formatted git commit message private CheckinOptionsFactory GetCheckinOptionsFactory() { - return new CheckinOptionsFactory(new StringWriter(), mocks.Get()); + return new CheckinOptionsFactory(mocks.Get()); } } } diff --git a/GitTfsTest/paket.references b/GitTfsTest/paket.references index 650bfa4d9..6618cc5c2 100644 --- a/GitTfsTest/paket.references +++ b/GitTfsTest/paket.references @@ -2,4 +2,5 @@ LibGit2Sharp xunit xunit.extensions xunit.runner.visualstudio -xunit.runners \ No newline at end of file +xunit.runners +nlog \ No newline at end of file diff --git a/doc/release-notes/NEXT.md b/doc/release-notes/NEXT.md index 6523cf63f..692252852 100644 --- a/doc/release-notes/NEXT.md +++ b/doc/release-notes/NEXT.md @@ -1 +1,2 @@ * Custom TFS check-in notes are not exported to commit message (#1004, @EdwinEngelen) +* Log in a file git-tfs actions (#999, @pmiossec) diff --git a/paket.dependencies b/paket.dependencies index eae5f147d..d773e7369 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -4,6 +4,7 @@ source https://www.nuget.org/api/v2/ //because there is some subtleties on how we use it in our project: //https://github.com/git-tfs/git-tfs/blob/master/doc/paket.md +nuget nlog nuget NuGet.CommandLine nuget LibGit2Sharp 0.21.0.176 nuget Microsoft.TeamFoundationServer.Client 14.102.0 framework: >= net45 @@ -13,4 +14,4 @@ nuget xunit 1.9.2 framework: >= net40 nuget xunit.extensions 1.9.2 framework: >= net40 nuget xunit.runner.visualstudio 2.0.1 framework: >= net40 nuget xunit.runners 1.9.2 framework: >= net40 -nuget MSBuildTasks 1.4.0.45 framework: >= net40 +nuget MSBuildTasks 1.4.0.45 framework: >= net40 \ No newline at end of file diff --git a/paket.lock b/paket.lock index c260fffd0..108e1b14a 100644 --- a/paket.lock +++ b/paket.lock @@ -58,6 +58,7 @@ NUGET Microsoft.Win32.Primitives (4.0.1) - framework: >= net461 MSBuildTasks (1.4.0.45) - framework: >= net40 Newtonsoft.Json (9.0.1) - framework: >= net45 + NLog (4.3.9) NuGet.CommandLine (3.3) System.Collections (4.0.11) - framework: >= net461 System.Collections.Concurrent (4.0.12) - framework: >= net461