private int PerformCheckin(TfsChangesetInfo parentChangeset, string refToCheckin) { var newChangesetId = DoCheckin(parentChangeset, refToCheckin); if (_checkinOptions.NoMerge) { _stdout.WriteLine("TFS Changeset #" + newChangesetId + " was created."); parentChangeset.Remote.Fetch(); } else { _stdout.WriteLine("TFS Changeset #" + newChangesetId + " was created. Marking it as a merge commit..."); parentChangeset.Remote.FetchWithMerge(newChangesetId, refToCheckin); if (refToCheckin == "HEAD") { parentChangeset.Remote.Repository.CommandNoisy("merge", parentChangeset.Remote.MaxCommitHash); } } Trace.WriteLine("Cleaning..."); parentChangeset.Remote.CleanupWorkspaceDirectory(); return(GitTfsExitCodes.OK); }
private ITfsChangeset BuildTfsChangeset(ScriptedChangeset changeset, IGitTfsRemote remote) { TfsChangesetInfo tfsChangesetInfo = new TfsChangesetInfo { ChangesetId = changeset.Id, Remote = remote }; var tfsChangeset = _container.With <ITfsHelper>(this).With <IChangeset>(new Changeset(_versionControlServer, changeset)).With(tfsChangesetInfo).GetInstance <TfsChangeset>(); return(tfsChangeset); }
public void Policy_failed_and_Force_without_an_OverrideReason() { var logger = new StringWriter(); Trace.Listeners.Add(new TextWriterTraceListener(logger)); IWorkspace workspace = MockRepository.GenerateStub <IWorkspace>(); string localDirectory = string.Empty; TfsChangesetInfo contextVersion = MockRepository.GenerateStub <TfsChangesetInfo>(); IGitTfsRemote remote = MockRepository.GenerateStub <IGitTfsRemote>(); remote.Repository = MockRepository.GenerateStub <IGitRepository>(); CheckinOptions checkinOptions = new CheckinOptions(); ITfsHelper tfsHelper = MockRepository.GenerateStub <ITfsHelper>(); CheckinPolicyEvaluator policyEvaluator = new CheckinPolicyEvaluator(); TfsWorkspace tfsWorkspace = new TfsWorkspace(workspace, localDirectory, contextVersion, remote, checkinOptions, tfsHelper, policyEvaluator); IPendingChange pendingChange = MockRepository.GenerateStub <IPendingChange>(); IPendingChange[] allPendingChanges = new IPendingChange[] { pendingChange }; workspace.Stub(w => w.GetPendingChanges()).Return(allPendingChanges); ICheckinEvaluationResult checkinEvaluationResult = new StubbedCheckinEvaluationResult() .WithPoilicyFailure("No work items associated."); checkinOptions.Force = true; workspace.Stub(w => w.EvaluateCheckin( Arg <TfsCheckinEvaluationOptions> .Is.Anything, Arg <IPendingChange[]> .Is.Anything, Arg <IPendingChange[]> .Is.Anything, Arg <string> .Is.Anything, Arg <string> .Is.Anything, Arg <ICheckinNote> .Is.Anything, Arg <IEnumerable <IWorkItemCheckinInfo> > .Is.Anything)) .Return(checkinEvaluationResult); workspace.Expect(w => w.Checkin( Arg <IPendingChange[]> .Is.Anything, Arg <string> .Is.Anything, Arg <string> .Is.Anything, Arg <ICheckinNote> .Is.Anything, Arg <IEnumerable <IWorkItemCheckinInfo> > .Is.Anything, Arg <TfsPolicyOverrideInfo> .Is.Anything, Arg <bool> .Is.Anything)) .Return(0); var ex = Assert.Throws <GitTfsException>(() => { var result = tfsWorkspace.Checkin(checkinOptions); }); Assert.Equal("A reason must be supplied (-f REASON) to override the policy violations.", ex.Message); Assert.Contains("[ERROR] Policy: No work items associated.", logger.ToString()); }
protected override int DoCheckin(TfsChangesetInfo changeset, string refToCheckin) { if (!changeset.Remote.Tfs.CanShowCheckinDialog) { throw new GitTfsException( "checkintool does not work with this TFS version (" + changeset.Remote.Tfs.TfsClientLibraryVersion + ").", new[] { "Try installing the VS2010 edition of Team Explorer." }); } return(changeset.Remote.CheckinTool(refToCheckin, changeset)); }
private int PerformRCheckin(TfsChangesetInfo parentChangeset, string refToCheckin) { if (_globals.Repository.IsBare) { AutoRebase = false; } if (_globals.Repository.WorkingCopyHasUnstagedOrUncommitedChanges) { throw new GitTfsException("error: You have local changes; rebase-workflow checkin only possible with clean working directory.") .WithRecommendation("Try 'git stash' to stash your local changes and checkin again."); } // get latest 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) { if (AutoRebase) { _globals.Repository.CommandNoisy("rebase", "--preserve-merges", parentChangeset.Remote.RemoteRef); parentChangeset = _globals.Repository.GetTfsCommit(parentChangeset.Remote.MaxCommitHash); } else { if (_globals.Repository.IsBare) { _globals.Repository.UpdateRef(refToCheckin, parentChangeset.Remote.MaxCommitHash); } throw new GitTfsException("error: New TFS changesets were found.") .WithRecommendation("Try to rebase HEAD onto latest TFS checkin and repeat rcheckin or alternatively checkins"); } } IEnumerable <GitCommit> commitsToCheckin = _globals.Repository.FindParentCommits(refToCheckin, parentChangeset.Remote.MaxCommitHash); Trace.WriteLine("Commit to checkin count:" + commitsToCheckin.Count()); if (!commitsToCheckin.Any()) { throw new GitTfsException("error: latest TFS commit should be parent of commits being checked in"); } Trace.WriteLine("Checking locks"); if (CheckLock) { CheckLocks(parentChangeset, refToCheckin); } SetupMetadataExport(parentChangeset.Remote); return(_PerformRCheckinQuick(parentChangeset, refToCheckin, commitsToCheckin)); }
private void CheckLocks(TfsChangesetInfo parentChangeset, string refToCheckin) { string[] changedFiles = _globals.Repository.GetChangedFiles(parentChangeset.GitCommit, refToCheckin) .Select(x => { if (x is Core.Changes.Git.Modify) { return(((Core.Changes.Git.Modify)x).Path); } else if (x is Core.Changes.Git.RenameEdit) { return(((Core.Changes.Git.RenameEdit)x).Path); } else { return(null); } }) .Where(x => !String.IsNullOrEmpty(x)) .ToArray() ; if (changedFiles.Length == 0) { return; } var pendingSets = parentChangeset.Remote.QueryPendingSets( parentChangeset, changedFiles, Core.TfsInterop.TfsRecursionType.None, queryWorkspace: null, queryUser: null ); var lockedChanges = pendingSets .SelectMany(set => set.PendingChanges, (set, change) => Tuple.Create(set, change)) .Where(change => change.Item2.LockLevel != Core.TfsInterop.TfsLockLevel.None) .Select(change => String.Format( "{0} has been locked ({1}) by {2};{3}", change.Item2.ServerItem, change.Item2.LockLevel.ToString(), change.Item1.OwnerDisplayName, change.Item1.Computer ) ) .ToArray(); if (lockedChanges.Length > 0) { throw new GitTfsException(String.Format("error: Some files are exclusive locked.\n{0}", String.Join("\n", lockedChanges))); } }
public void ShouldFailWithMoreThanOneParents() { mocks.Get <Globals>().Repository = mocks.Get <IGitRepository>(); var parentChangesets = new TfsChangesetInfo() { Remote = mocks.Get <IGitTfsRemote>() }; mocks.Get <IGitRepository>().Stub(x => x.GetLastParentTfsCommits("my-head")) .Return(new[] { parentChangesets, parentChangesets }); Assert.AreNotEqual(GitTfsExitCodes.OK, mocks.ClassUnderTest.Run("don't care", "my-head")); }
public void WithWorkspace(string directory, IGitTfsRemote remote, TfsChangesetInfo versionToFetch, Action <ITfsWorkspace> action) { Trace.WriteLine("Setting up a TFS workspace at " + directory); var fakeWorkspace = new FakeWorkspace(directory, remote.TfsRepositoryPath); var workspace = _container.With("localDirectory").EqualTo(directory) .With("remote").EqualTo(remote) .With("contextVersion").EqualTo(versionToFetch) .With("workspace").EqualTo(fakeWorkspace) .With("tfsHelper").EqualTo(this) .GetInstance <TfsWorkspace>(); action(workspace); }
public void Policy_failed_and_Force_with_an_OverrideReason() { IWorkspace workspace = MockRepository.GenerateStub <IWorkspace>(); string localDirectory = string.Empty; TextWriter writer = new StringWriter(); TfsChangesetInfo contextVersion = MockRepository.GenerateStub <TfsChangesetInfo>(); IGitTfsRemote remote = MockRepository.GenerateStub <IGitTfsRemote>(); remote.Repository = MockRepository.GenerateStub <IGitRepository>(); CheckinOptions checkinOptions = new CheckinOptions(); ITfsHelper tfsHelper = MockRepository.GenerateStub <ITfsHelper>(); CheckinPolicyEvaluator policyEvaluator = new CheckinPolicyEvaluator(); TfsWorkspace tfsWorkspace = new TfsWorkspace(workspace, localDirectory, writer, contextVersion, remote, checkinOptions, tfsHelper, policyEvaluator); IPendingChange pendingChange = MockRepository.GenerateStub <IPendingChange>(); IPendingChange[] allPendingChanges = new IPendingChange[] { pendingChange }; workspace.Stub(w => w.GetPendingChanges()).Return(allPendingChanges); ICheckinEvaluationResult checkinEvaluationResult = new StubbedCheckinEvaluationResult() .WithPoilicyFailure("No work items associated."); checkinOptions.Force = true; checkinOptions.OverrideReason = "no work items"; workspace.Stub(w => w.EvaluateCheckin( Arg <TfsCheckinEvaluationOptions> .Is.Anything, Arg <IPendingChange[]> .Is.Anything, Arg <IPendingChange[]> .Is.Anything, Arg <string> .Is.Anything, Arg <string> .Is.Anything, Arg <ICheckinNote> .Is.Anything, Arg <IEnumerable <IWorkItemCheckinInfo> > .Is.Anything)) .Return(checkinEvaluationResult); workspace.Expect(w => w.Checkin( Arg <IPendingChange[]> .Is.Anything, Arg <string> .Is.Anything, Arg <string> .Is.Anything, Arg <ICheckinNote> .Is.Anything, Arg <IEnumerable <IWorkItemCheckinInfo> > .Is.Anything, Arg <TfsPolicyOverrideInfo> .Is.Anything, Arg <bool> .Is.Anything)) .Return(1); var result = tfsWorkspace.Checkin(checkinOptions); Assert.Contains("[OVERRIDDEN] Policy: No work items associated.", writer.ToString()); }
protected override int DoCheckin(TfsChangesetInfo changeset, string refToCheckin) { if (!changeset.Remote.Tfs.CanShowCheckinDialog) { throw new GitTfsException( "checkintool does not work with this TFS version (" + changeset.Remote.Tfs.TfsClientLibraryVersion + ").", new[] { "Try installing the Team Explorer matching the TFS client libraries", "Alternatively, set the GIT_TFS_CLIENT environment variable to a supported/installed Visual Studio version", }); } return(changeset.Remote.CheckinTool(refToCheckin, changeset)); }
public void Checkin_failed() { IWorkspace workspace = MockRepository.GenerateStub <IWorkspace>(); string localDirectory = string.Empty; TextWriter writer = new StringWriter(); TfsChangesetInfo contextVersion = MockRepository.GenerateStub <TfsChangesetInfo>(); IGitTfsRemote remote = MockRepository.GenerateStub <IGitTfsRemote>(); remote.Repository = MockRepository.GenerateStub <IGitRepository>(); CheckinOptions checkinOptions = new CheckinOptions(); ITfsHelper tfsHelper = MockRepository.GenerateStub <ITfsHelper>(); CheckinPolicyEvaluator policyEvaluator = new CheckinPolicyEvaluator(); TfsWorkspace tfsWorkspace = new TfsWorkspace(workspace, localDirectory, writer, contextVersion, remote, checkinOptions, tfsHelper, policyEvaluator); IPendingChange pendingChange = MockRepository.GenerateStub <IPendingChange>(); IPendingChange[] allPendingChanges = new IPendingChange[] { pendingChange }; workspace.Stub(w => w.GetPendingChanges()).Return(allPendingChanges); ICheckinEvaluationResult checkinEvaluationResult = new StubbedCheckinEvaluationResult(); workspace.Stub(w => w.EvaluateCheckin( Arg <TfsCheckinEvaluationOptions> .Is.Anything, Arg <IPendingChange[]> .Is.Anything, Arg <IPendingChange[]> .Is.Anything, Arg <string> .Is.Anything, Arg <string> .Is.Anything, Arg <ICheckinNote> .Is.Anything, Arg <IEnumerable <IWorkItemCheckinInfo> > .Is.Anything)) .Return(checkinEvaluationResult); workspace.Expect(w => w.Checkin( Arg <IPendingChange[]> .Is.Anything, Arg <string> .Is.Anything, Arg <string> .Is.Anything, Arg <ICheckinNote> .Is.Anything, Arg <IEnumerable <IWorkItemCheckinInfo> > .Is.Anything, Arg <TfsPolicyOverrideInfo> .Is.Anything, Arg <bool> .Is.Anything)) .Return(0); var ex = Assert.Throws <GitTfsException>(() => { var result = tfsWorkspace.Checkin(checkinOptions); }); Assert.Equal("Checkin failed!", ex.Message); }
private int PerformRCheckin(TfsChangesetInfo parentChangeset, string refToCheckin) { var tfsRemote = parentChangeset.Remote; var repo = tfsRemote.Repository; if (repo.IsBare) { AutoRebase = false; } if (repo.WorkingCopyHasUnstagedOrUncommitedChanges) { throw new GitTfsException("error: You have local changes; rebase-workflow checkin only possible with clean working directory.") .WithRecommendation("Try 'git stash' to stash your local changes and checkin again."); } // get latest changes from TFS to minimize possibility of late conflict _stdout.WriteLine("Fetching changes from TFS to minimize possibility of late conflict..."); parentChangeset.Remote.Fetch(); if (parentChangeset.ChangesetId != parentChangeset.Remote.MaxChangesetId) { if (Quick && AutoRebase) { tfsRemote.Repository.CommandNoisy("rebase", "--preserve-merges", tfsRemote.RemoteRef); parentChangeset = _globals.Repository.GetTfsCommit(parentChangeset.Remote.MaxCommitHash); } else { if (repo.IsBare) { repo.UpdateRef(refToCheckin, parentChangeset.Remote.MaxCommitHash); } throw new GitTfsException("error: New TFS changesets were found.") .WithRecommendation("Try to rebase HEAD onto latest TFS checkin and repeat rcheckin or alternatively checkin s"); } } string tfsLatest = parentChangeset.Remote.MaxCommitHash; // we could rcheckin only if tfsLatest changeset is a parent of HEAD // so that we could rebase after each single checkin without conflicts if (!String.IsNullOrWhiteSpace(repo.CommandOneline("rev-list", tfsLatest, "^" + refToCheckin))) { throw new GitTfsException("error: latest TFS commit should be parent of commits being checked in"); } return((Quick || repo.IsBare) ? _PerformRCheckinQuick(parentChangeset, refToCheckin) : _PerformRCheckin(parentChangeset, refToCheckin)); }
private int _PerformRCheckin(TfsChangesetInfo parentChangeset, string refToCheckin) { var tfsRemote = parentChangeset.Remote; var repo = tfsRemote.Repository; string tfsLatest = parentChangeset.Remote.MaxCommitHash; RCheckinCommit rc = new RCheckinCommit(repo); while (true) { // determine first descendant of tfsLatest string revList = repo.CommandOneline("rev-list", "--parents", "--ancestry-path", "--first-parent", "--reverse", tfsLatest + ".." + refToCheckin); if (String.IsNullOrWhiteSpace(revList)) { _stdout.WriteLine("No more to rcheckin."); Trace.WriteLine("Cleaning..."); tfsRemote.CleanupWorkspaceDirectory(); return(GitTfsExitCodes.OK); } rc.ExtractCommit(revList, tfsLatest); rc.BuildCommitMessage(!_checkinOptions.NoGenerateCheckinComment, tfsLatest); string target = rc.Sha; string tfsRepositoryPathOfMergedBranch = FindTfsRepositoryPathOfMergedBranch(tfsRemote, rc.Parents, target); var commitSpecificCheckinOptions = _checkinOptionsFactory.BuildCommitSpecificCheckinOptions(_checkinOptions, rc.Message, rc.Commit); _stdout.WriteLine("Starting checkin of {0} '{1}'", target.Substring(0, 8), commitSpecificCheckinOptions.CheckinComment); long newChangesetId = tfsRemote.Checkin(rc.Sha, parentChangeset, commitSpecificCheckinOptions, tfsRepositoryPathOfMergedBranch); tfsRemote.FetchWithMerge(newChangesetId, false, rc.Parents); if (tfsRemote.MaxChangesetId != newChangesetId) { throw new GitTfsException("error: New TFS changesets were found. Rcheckin was not finished."); } tfsLatest = tfsRemote.MaxCommitHash; parentChangeset = new TfsChangesetInfo { ChangesetId = newChangesetId, GitCommit = tfsLatest, Remote = tfsRemote }; _stdout.WriteLine("Done with {0}, rebasing tail onto new TFS-commit...", target); RebaseOnto(repo, tfsLatest, target); _stdout.WriteLine("Rebase done successfully."); } }
private string GetRemoteId(TfsChangesetInfo parent) { if (IsAvailable(GitTfsConstants.DefaultRepositoryId)) { return(GitTfsConstants.DefaultRepositoryId); } var hostname = new Uri(parent.Remote.TfsUrl).Host.Replace(".", "-"); var remoteId = hostname; var suffix = 0; while (!IsAvailable(remoteId)) { remoteId = hostname + "-" + (suffix++); } return(remoteId); }
private int _PerformRCheckin(TfsChangesetInfo parentChangeset, string refToCheckin, IEnumerable <GitCommit> commitsToCheckin) { var tfsRemote = parentChangeset.Remote; string tfsLatest = parentChangeset.Remote.MaxCommitHash; while (true) { // determine first descendant of tfsLatest var commit = commitsToCheckin.FirstOrDefault(); if (commit == null) { _stdout.WriteLine("No more to rcheckin."); Trace.WriteLine("Cleaning..."); tfsRemote.CleanupWorkspaceDirectory(); return(GitTfsExitCodes.OK); } var message = BuildCommitMessage(commit, !_checkinOptions.NoGenerateCheckinComment, tfsLatest); string target = commit.Sha; var parents = commit.Parents.Where(c => c.Sha != tfsLatest).ToArray(); string tfsRepositoryPathOfMergedBranch = FindTfsRepositoryPathOfMergedBranch(tfsRemote, parents, target); var commitSpecificCheckinOptions = _checkinOptionsFactory.BuildCommitSpecificCheckinOptions(_checkinOptions, message, commit); _stdout.WriteLine("Starting checkin of {0} '{1}'", target.Substring(0, 8), commitSpecificCheckinOptions.CheckinComment); long newChangesetId = tfsRemote.Checkin(commit.Sha, parentChangeset, commitSpecificCheckinOptions, tfsRepositoryPathOfMergedBranch); tfsRemote.FetchWithMerge(newChangesetId, false, parents.Select(c => c.Sha).ToArray()); if (tfsRemote.MaxChangesetId != newChangesetId) { throw new GitTfsException("error: New TFS changesets were found. Rcheckin was not finished."); } tfsLatest = tfsRemote.MaxCommitHash; parentChangeset = new TfsChangesetInfo { ChangesetId = newChangesetId, GitCommit = tfsLatest, Remote = tfsRemote }; _stdout.WriteLine("Done with {0}, rebasing tail onto new TFS-commit...", target); RebaseOnto(tfsLatest, target); _stdout.WriteLine("Rebase done successfully."); commitsToCheckin = _globals.Repository.FindParentCommits(refToCheckin, tfsLatest); } }
public void WithWorkspace(string localDirectory, IGitTfsRemote remote, TfsChangesetInfo versionToFetch, Action <ITfsWorkspace> action) { var workspace = GetWorkspace(localDirectory, remote.TfsRepositoryPath); try { var tfsWorkspace = _container.With("localDirectory").EqualTo(localDirectory) .With("remote").EqualTo(remote) .With("contextVersion").EqualTo(versionToFetch) .With("workspace").EqualTo(_bridge.Wrap <WrapperForWorkspace, Workspace>(workspace)) .GetInstance <TfsWorkspace>(); action(tfsWorkspace); } finally { workspace.Delete(); } }
public int Run(string shelvesetName, string destinationBranch) { if (string.IsNullOrEmpty(TfsBranch)) //If destination not on command line, set up defaults. { TfsBranch = _globals.RemoteId; //Default to main remote id. //Get the current checkout TfsChangesetInfo mostRecentUpdate = _globals.Repository.GetLastParentTfsCommits("HEAD").FirstOrDefault(); if (mostRecentUpdate != null) { TfsBranch = mostRecentUpdate.Remote.Id; } } var remote = _globals.Repository.ReadTfsRemote(TfsBranch); remote.Unshelve(Owner, shelvesetName, destinationBranch); _stdout.WriteLine("Created branch " + destinationBranch + " from shelveset \"" + shelvesetName + "\"."); return(GitTfsExitCodes.OK); }
public int Verify(TfsChangesetInfo changeset, bool ignorePathCaseMismatch) { 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()); var all = tfsTree.Keys.Union(gitTree.Keys); var inBoth = tfsTree.Keys.Intersect(gitTree.Keys); var tfsOnly = tfsTree.Keys.Except(gitTree.Keys); var gitOnly = gitTree.Keys.Except(tfsTree.Keys); var foundDiff = GitTfsExitCodes.OK; foreach (var file in all.OrderBy(x => x)) { if (tfsTree.ContainsKey(file)) { if (gitTree.ContainsKey(file)) { if (Compare(tfsTree[file], gitTree[file], ignorePathCaseMismatch)) { foundDiff = Math.Max(foundDiff, GitTfsExitCodes.VerifyContentMismatch); } } else { Trace.TraceInformation("Only in TFS: " + tfsTree[file].FullName); foundDiff = Math.Max(foundDiff, GitTfsExitCodes.VerifyFileMissing); } } else { Trace.TraceInformation("Only in git: " + gitTree[file].FullName); foundDiff = Math.Max(foundDiff, GitTfsExitCodes.VerifyFileMissing); } } if (foundDiff == GitTfsExitCodes.OK) { Trace.TraceInformation("No differences!"); } return(foundDiff); }
public void WithWorkspace(string localDirectory, IGitTfsRemote remote, TfsChangesetInfo versionToFetch, Action <ITfsWorkspace> action) { Trace.WriteLine("Setting up a TFS workspace at " + localDirectory); var workspace = GetWorkspace(new WorkingFolder(remote.TfsRepositoryPath, localDirectory)); try { var tfsWorkspace = _container.With("localDirectory").EqualTo(localDirectory) .With("remote").EqualTo(remote) .With("contextVersion").EqualTo(versionToFetch) .With("workspace").EqualTo(_bridge.Wrap <WrapperForWorkspace, Workspace>(workspace)) .With("tfsHelper").EqualTo(this) .GetInstance <TfsWorkspace>(); action(tfsWorkspace); } finally { workspace.Delete(); } }
public void Verify(TfsChangesetInfo changeset) { _stdout.WriteLine("Comparing TFS changeset " + changeset.ChangesetId + " to git commit " + changeset.GitCommit); var tfsTree = changeset.Remote.GetChangeset(changeset.ChangesetId).GetTree().ToDictionary(entry => entry.FullName.ToLowerInvariant()); var gitTree = changeset.Remote.Repository.GetCommit(changeset.GitCommit).GetTree().ToDictionary(entry => entry.Entry.FullName.ToLowerInvariant()); var all = tfsTree.Keys.Union(gitTree.Keys); var inBoth = tfsTree.Keys.Intersect(gitTree.Keys); var tfsOnly = tfsTree.Keys.Except(gitTree.Keys); var gitOnly = gitTree.Keys.Except(tfsTree.Keys); var foundDiff = false; foreach (var file in all.OrderBy(x => x)) { if (tfsTree.ContainsKey(file)) { if (gitTree.ContainsKey(file)) { if (Compare(tfsTree[file], gitTree[file])) { foundDiff = true; } } else { OnlyIn("TFS", tfsTree[file]); foundDiff = true; } } else { OnlyIn("git", gitTree[file]); foundDiff = true; } } if (!foundDiff) { _stdout.WriteLine("No differences!"); } }
public void Nothing_to_checkin() { IWorkspace workspace = MockRepository.GenerateStub <IWorkspace>(); string localDirectory = string.Empty; TextWriter writer = new StringWriter(); TfsChangesetInfo contextVersion = MockRepository.GenerateStub <TfsChangesetInfo>(); IGitTfsRemote remote = MockRepository.GenerateStub <IGitTfsRemote>(); CheckinOptions checkinOptions = new CheckinOptions(); ITfsHelper tfsHelper = MockRepository.GenerateStub <ITfsHelper>(); CheckinPolicyEvaluator policyEvaluator = new CheckinPolicyEvaluator(); TfsWorkspace tfsWorkspace = new TfsWorkspace(workspace, localDirectory, writer, contextVersion, remote, checkinOptions, tfsHelper, policyEvaluator); workspace.Stub(w => w.GetPendingChanges()).Return(null); var ex = Assert.Throws <GitTfsException>(() => { var result = tfsWorkspace.Checkin(checkinOptions); }); Assert.Equal("Nothing to checkin!", ex.Message); }
public void WithWorkspace(string localDirectory, IGitTfsRemote remote, TfsChangesetInfo versionToFetch, Action <ITfsWorkspace> action) { Workspace workspace; if (!_workspaces.TryGetValue(remote.Id, out workspace)) { Trace.WriteLine("Setting up a TFS workspace at " + localDirectory); _workspaces.Add(remote.Id, workspace = GetWorkspace(localDirectory, remote.TfsRepositoryPath)); Janitor.CleanThisUpWhenWeClose(() => { Trace.WriteLine("Deleting workspace " + workspace.Name); workspace.Delete(); }); } var tfsWorkspace = _container.With("localDirectory").EqualTo(localDirectory) .With("remote").EqualTo(remote) .With("contextVersion").EqualTo(versionToFetch) .With("workspace").EqualTo(_bridge.Wrap <WrapperForWorkspace, Workspace>(workspace)) .With("tfsHelper").EqualTo(this) .GetInstance <TfsWorkspace>(); action(tfsWorkspace); }
private string GetRemoteId(TfsChangesetInfo parent) { if (IsAvailable(GitTfsConstants.DefaultRepositoryId)) { return(GitTfsConstants.DefaultRepositoryId); } //Remove '$/'! var expectedRemoteId = parent.Remote.TfsRepositoryPath.Substring(2).Trim('/'); var indexOfSlash = expectedRemoteId.IndexOf('/'); if (indexOfSlash != 0) { expectedRemoteId = expectedRemoteId.Substring(indexOfSlash + 1); } var remoteId = expectedRemoteId.ToGitRefName(); var suffix = 0; while (!IsAvailable(remoteId)) { remoteId = expectedRemoteId + "-" + (suffix++); } return(remoteId); }
private int PerformRCheckin(TfsChangesetInfo parentChangeset) { var tfsRemote = parentChangeset.Remote; var repo = tfsRemote.Repository; if (repo.WorkingCopyHasUnstagedOrUncommitedChanges) { throw new GitTfsException("error: You have local changes; rebase-workflow checkin only possible with clean working directory.") .WithRecommendation("Try 'git stash' to stash your local changes and checkin again."); } // get latest changes from TFS to minimize possibility of late conflict _stdout.WriteLine("Fetching changes from TFS to minimize possibility of late conflict..."); parentChangeset.Remote.Fetch(); if (parentChangeset.ChangesetId != parentChangeset.Remote.MaxChangesetId) { throw new GitTfsException("error: New TFS changesets were found.") .WithRecommendation("Try to rebase HEAD onto latest TFS checkin and repeat rcheckin or alternatively checkin s"); } string tfsLatest = parentChangeset.Remote.MaxCommitHash; // we could rcheckin only if tfsLatest changeset is a parent of HEAD // so that we could rebase after each single checkin without conflicts if (!String.IsNullOrWhiteSpace(repo.CommandOneline("rev-list", tfsLatest, "^HEAD"))) { throw new GitTfsException("error: latest TFS commit should be parent of commits being checked in"); } if (Quick) { string[] revList = null; repo.CommandOutputPipe(tr => revList = tr.ReadToEnd().Split('\n').Where(s => !String.IsNullOrWhiteSpace(s)).ToArray(), "rev-list", "--parents", "--ancestry-path", "--first-parent", "--reverse", tfsLatest + "..HEAD"); string currentParent = tfsLatest; foreach (string commitWithParents in revList) { string[] strs = commitWithParents.Split(' '); string target = strs[0]; string[] gitParents = strs.AsEnumerable().Skip(1).Where(hash => hash != currentParent).ToArray(); string commitMessage = repo.GetCommitMessage(target, currentParent).Trim(' ', '\r', '\n'); var commitSpecificCheckinOptions = _checkinOptionsFactory.BuildCommitSpecificCheckinOptions(_checkinOptions, commitMessage); _stdout.WriteLine("Starting checkin of {0} '{1}'", target.Substring(0, 8), commitSpecificCheckinOptions.CheckinComment); long newChangesetId = tfsRemote.Checkin(target, currentParent, parentChangeset, commitSpecificCheckinOptions); tfsRemote.FetchWithMerge(newChangesetId, gitParents); if (tfsRemote.MaxChangesetId != newChangesetId) { throw new GitTfsException("error: New TFS changesets were found. Rcheckin was not finished."); } currentParent = target; parentChangeset = new TfsChangesetInfo { ChangesetId = newChangesetId, GitCommit = tfsRemote.MaxCommitHash, Remote = tfsRemote }; _stdout.WriteLine("Done with {0}.", target); } _stdout.WriteLine("No more to rcheckin."); return(GitTfsExitCodes.OK); } else { while (true) { // determine first descendant of tfsLatest string revList = repo.CommandOneline("rev-list", "--parents", "--ancestry-path", "--first-parent", "--reverse", tfsLatest + "..HEAD"); if (String.IsNullOrWhiteSpace(revList)) { _stdout.WriteLine("No more to rcheckin."); return(GitTfsExitCodes.OK); } string[] strs = revList.Split(' '); string target = strs[0]; string[] gitParents = strs.AsEnumerable().Skip(1).Where(hash => hash != tfsLatest).ToArray(); string commitMessage = repo.GetCommitMessage(target, tfsLatest).Trim(' ', '\r', '\n'); var commitSpecificCheckinOptions = _checkinOptionsFactory.BuildCommitSpecificCheckinOptions(_checkinOptions, commitMessage); _stdout.WriteLine("Starting checkin of {0} '{1}'", target.Substring(0, 8), commitSpecificCheckinOptions.CheckinComment); long newChangesetId = tfsRemote.Checkin(target, parentChangeset, commitSpecificCheckinOptions); tfsRemote.FetchWithMerge(newChangesetId, gitParents); if (tfsRemote.MaxChangesetId != newChangesetId) { throw new GitTfsException("error: New TFS changesets were found. Rcheckin was not finished."); } tfsLatest = tfsRemote.MaxCommitHash; parentChangeset = new TfsChangesetInfo { ChangesetId = newChangesetId, GitCommit = tfsLatest, Remote = tfsRemote }; _stdout.WriteLine("Done with {0}, rebasing tail onto new TFS-commit...", target); repo.CommandNoisy("rebase", "--preserve-merges", "--onto", tfsLatest, target); _stdout.WriteLine("Rebase done successfully."); } } }
public void WithWorkspace(string localDirectory, IGitTfsRemote remote, IEnumerable <Tuple <string, string> > mappings, TfsChangesetInfo versionToFetch, Action <ITfsWorkspace> action) { Workspace workspace; if (!_workspaces.TryGetValue(remote.Id, out workspace)) { Trace.WriteLine("Setting up a TFS workspace with subtrees at " + localDirectory); var folders = mappings.Select(x => new WorkingFolder(x.Item1, Path.Combine(localDirectory, x.Item2))).ToArray(); _workspaces.Add(remote.Id, workspace = GetWorkspace(folders)); Janitor.CleanThisUpWhenWeClose(() => { Trace.WriteLine("Deleting workspace " + workspace.Name); workspace.Delete(); }); } var tfsWorkspace = _container.With("localDirectory").EqualTo(localDirectory) .With("remote").EqualTo(remote) .With("contextVersion").EqualTo(versionToFetch) .With("workspace").EqualTo(_bridge.Wrap <WrapperForWorkspace, Workspace>(workspace)) .With("tfsHelper").EqualTo(this) .GetInstance <TfsWorkspace>(); action(tfsWorkspace); }
protected override int DoCheckin(TfsChangesetInfo changeset, string refToCheckin) { return(changeset.Remote.Checkin(refToCheckin, changeset, _checkinOptions)); }
private int _PerformRCheckinQuick(TfsChangesetInfo parentChangeset, string refToCheckin) { var tfsRemote = parentChangeset.Remote; var repo = tfsRemote.Repository; string tfsLatest = parentChangeset.Remote.MaxCommitHash; string[] revList = null; repo.CommandOutputPipe(tr => revList = tr.ReadToEnd().Split('\n').Where(s => !String.IsNullOrWhiteSpace(s)).ToArray(), "rev-list", "--parents", "--ancestry-path", "--first-parent", "--reverse", tfsLatest + ".." + refToCheckin); string currentParent = tfsLatest; long newChangesetId = 0; RCheckinCommit rc = new RCheckinCommit(repo); foreach (string commitWithParents in revList) { rc.ExtractCommit(commitWithParents, currentParent); rc.BuildCommitMessage(!_checkinOptions.NoGenerateCheckinComment, currentParent); string target = rc.Sha; string tfsRepositoryPathOfMergedBranch = FindTfsRepositoryPathOfMergedBranch(tfsRemote, rc.Parents, target); var commitSpecificCheckinOptions = _checkinOptionsFactory.BuildCommitSpecificCheckinOptions(_checkinOptions, rc.Message, rc.Commit); _stdout.WriteLine("Starting checkin of {0} '{1}'", target.Substring(0, 8), commitSpecificCheckinOptions.CheckinComment); try { newChangesetId = tfsRemote.Checkin(target, currentParent, parentChangeset, commitSpecificCheckinOptions, tfsRepositoryPathOfMergedBranch); var fetchResult = tfsRemote.FetchWithMerge(newChangesetId, false, rc.Parents); if (fetchResult.NewChangesetCount != 1) { var lastCommit = repo.FindCommitHashByChangesetId(newChangesetId); RebaseOnto(repo, lastCommit, target); if (AutoRebase) { tfsRemote.Repository.CommandNoisy("rebase", "--preserve-merges", tfsRemote.RemoteRef); } else { throw new GitTfsException("error: New TFS changesets were found. Rcheckin was not finished."); } } currentParent = target; parentChangeset = new TfsChangesetInfo { ChangesetId = newChangesetId, GitCommit = tfsRemote.MaxCommitHash, Remote = tfsRemote }; _stdout.WriteLine("Done with {0}.", target); } catch (Exception) { if (newChangesetId != 0) { var lastCommit = repo.FindCommitHashByChangesetId(newChangesetId); RebaseOnto(repo, lastCommit, currentParent); } throw; } } if (repo.IsBare) { repo.UpdateRef(refToCheckin, tfsRemote.MaxCommitHash); } else { repo.ResetHard(tfsRemote.MaxCommitHash); } _stdout.WriteLine("No more to rcheckin."); Trace.WriteLine("Cleaning..."); tfsRemote.CleanupWorkspaceDirectory(); return(GitTfsExitCodes.OK); }
private int _PerformRCheckinQuick(TfsChangesetInfo parentChangeset, string refToCheckin, IEnumerable <GitCommit> commitsToCheckin) { var tfsRemote = parentChangeset.Remote; string currentParent = parentChangeset.Remote.MaxCommitHash; int newChangesetId = 0; foreach (var commit in commitsToCheckin) { var message = BuildCommitMessage(commit, !_checkinOptions.NoGenerateCheckinComment, currentParent); string target = commit.Sha; var parents = commit.Parents.Where(c => c.Sha != currentParent).ToArray(); string tfsRepositoryPathOfMergedBranch = _checkinOptions.NoMerge ? null : FindTfsRepositoryPathOfMergedBranch(tfsRemote, parents, target); var commitSpecificCheckinOptions = _checkinOptionsFactory.BuildCommitSpecificCheckinOptions(_checkinOptions, message, commit, _authors); Trace.TraceInformation("Starting checkin of {0} '{1}'", target.Substring(0, 8), commitSpecificCheckinOptions.CheckinComment); try { newChangesetId = tfsRemote.Checkin(target, currentParent, parentChangeset, commitSpecificCheckinOptions, tfsRepositoryPathOfMergedBranch); var fetchResult = tfsRemote.FetchWithMerge(false, newChangesetId, false, parents.Select(c => c.Sha).ToArray()); if (fetchResult.NewChangesetCount != 1) { var lastCommit = _globals.Repository.FindCommitHashByChangesetId(newChangesetId); RebaseOnto(lastCommit, target); if (AutoRebase) { tfsRemote.Repository.CommandNoisy("rebase", "--preserve-merges", tfsRemote.RemoteRef); } else { throw new GitTfsException("error: New TFS changesets were found. Rcheckin was not finished."); } } currentParent = target; parentChangeset = new TfsChangesetInfo { ChangesetId = newChangesetId, GitCommit = tfsRemote.MaxCommitHash, Remote = tfsRemote }; Trace.TraceInformation("Done with {0}.", target); } catch (Exception) { if (newChangesetId != 0) { var lastCommit = _globals.Repository.FindCommitHashByChangesetId(newChangesetId); RebaseOnto(lastCommit, currentParent); } throw; } } if (_globals.Repository.IsBare) { _globals.Repository.UpdateRef(refToCheckin, tfsRemote.MaxCommitHash); } else { _globals.Repository.ResetHard(tfsRemote.MaxCommitHash); } Trace.TraceInformation("No more to rcheckin."); Trace.WriteLine("Cleaning..."); tfsRemote.CleanupWorkspaceDirectory(); return(GitTfsExitCodes.OK); }
protected abstract int DoCheckin(TfsChangesetInfo changeset, string refToCheckin);
protected override long DoCheckin(TfsChangesetInfo changeset, string refToCheckin) { return(changeset.Remote.Checkin(refToCheckin, changeset)); }