From 1e043a0c7aeadf05bb6adbfbb401b734c939702b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=96sterlund?= Date: Fri, 8 Mar 2019 12:54:46 +0100 Subject: [PATCH] Stop using property `InitialChangeset` for branch information. The global property `InitialChangeset` is used to store the first changeset the user want to clone from. But this was also in some situations used to store the first changeset of a branch. This cause a problem as this property is global and will be applied to all branches. If `InitialChangeset` is set for a branch, the next cloned branch can not get the changesets before the changeset given this `InitialChangeset` if it is not updated for that branch to. It is problematic to use a property for different information. --- doc/release-notes/NEXT.md | 4 +++- src/GitTfs/Commands/InitBranch.cs | 2 +- src/GitTfs/Core/DerivedGitTfsRemote.cs | 4 ++-- src/GitTfs/Core/GitTfsRemote.cs | 17 +++++++++++------ src/GitTfs/Core/IGitTfsRemote.cs | 4 ++-- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/doc/release-notes/NEXT.md b/doc/release-notes/NEXT.md index ce518510..c167f5da 100644 --- a/doc/release-notes/NEXT.md +++ b/doc/release-notes/NEXT.md @@ -4,4 +4,6 @@ * Add .net462 and windows10 long path support. See [doc to enable it](../blob/master/doc/Set-custom-workspace.md). (#1221 by @pmiossec) * Fix bug where checkin attempts to remove a non-empty directory. (#1249 by @m-akinc) * Line endings are now properly normalized when pushing changes to TFS if core.autocrlf is set to true (#1210 by @JeffCyr) -* Fix merge commits connecting to wrong parent +* Fix merge commits connecting to wrong parent (#1264 by DotNetSparky) +* Now possible to clone a deleted branch (#1263 by magol) +* Fix a issue that commits in a branch are lost if they are older then the first commit in a branch that are merging from this branch. (#1263 by magol) diff --git a/src/GitTfs/Commands/InitBranch.cs b/src/GitTfs/Commands/InitBranch.cs index 77c54174..7b191abc 100644 --- a/src/GitTfs/Commands/InitBranch.cs +++ b/src/GitTfs/Commands/InitBranch.cs @@ -149,7 +149,7 @@ namespace GitTfs.Commands // If this branch's branch point is past the first commit, indicate this so Fetch can start from that point if (rootBranch.TargetBranchChangesetId > -1) { - branchTfsRemote.SetInitialChangeset(rootBranch.TargetBranchChangesetId); + branchTfsRemote.SetFirstChangeset(rootBranch.TargetBranchChangesetId); } if (rootBranch.IsRenamedBranch || !NoFetch) diff --git a/src/GitTfs/Core/DerivedGitTfsRemote.cs b/src/GitTfs/Core/DerivedGitTfsRemote.cs index 66cf810a..0145eb52 100644 --- a/src/GitTfs/Core/DerivedGitTfsRemote.cs +++ b/src/GitTfs/Core/DerivedGitTfsRemote.cs @@ -190,12 +190,12 @@ namespace GitTfs.Core public bool ExportMetadatas { get; set; } public Dictionary ExportWorkitemsMapping { get; set; } - public int? GetInitialChangeset() + public int? GetFirstChangeset() { throw DerivedRemoteException; } - public void SetInitialChangeset(int? changesetId) + public void SetFirstChangeset(int? changesetId) { throw DerivedRemoteException; } diff --git a/src/GitTfs/Core/GitTfsRemote.cs b/src/GitTfs/Core/GitTfsRemote.cs index 909a4ebf..44ba761e 100644 --- a/src/GitTfs/Core/GitTfsRemote.cs +++ b/src/GitTfs/Core/GitTfsRemote.cs @@ -18,6 +18,7 @@ namespace GitTfs.Core private readonly Globals _globals; private readonly RemoteOptions _remoteOptions; private readonly ConfigProperties _properties; + private int? firstChangesetId; private int? maxChangesetId; private string maxCommitHash; private bool isTfsAuthenticated; @@ -73,14 +74,15 @@ namespace GitTfs.Core get { return false; } } - public int? GetInitialChangeset() + public int? GetFirstChangeset() { - return _properties.InitialChangeset; + return firstChangesetId; } - public void SetInitialChangeset(int? changesetId) + public void SetFirstChangeset(int? changesetId) { - _properties.InitialChangeset = changesetId; + Trace.WriteLine($"Set first changeset in branch to C{changesetId}"); + firstChangesetId = changesetId; } public bool IsSubtree { get; private set; } @@ -745,8 +747,11 @@ namespace GitTfs.Core // only the folder creation and deletion operations due to the lowerBound being // detected as the root-side of the commit +1 (C1+1=C2) instead of referencing // the branch-side of the branching operation [C4]. - if (_properties.InitialChangeset.HasValue) - lowerBoundChangesetId = Math.Max(MaxChangesetId + 1, _properties.InitialChangeset.Value); + if (_properties.InitialChangeset.HasValue || firstChangesetId.HasValue) + { + var firstChangesetInBranch = Math.Max(_properties.InitialChangeset ?? int.MinValue, firstChangesetId ?? int.MinValue); + lowerBoundChangesetId = Math.Max(MaxChangesetId + 1, firstChangesetInBranch); + } else lowerBoundChangesetId = MaxChangesetId + 1; Trace.WriteLine(RemoteRef + ": Getting changesets from " + lowerBoundChangesetId + diff --git a/src/GitTfs/Core/IGitTfsRemote.cs b/src/GitTfs/Core/IGitTfsRemote.cs index 90208467..590d0bd7 100644 --- a/src/GitTfs/Core/IGitTfsRemote.cs +++ b/src/GitTfs/Core/IGitTfsRemote.cs @@ -54,8 +54,8 @@ namespace GitTfs.Core string Prefix { get; } bool ExportMetadatas { get; set; } Dictionary ExportWorkitemsMapping { get; set; } - int? GetInitialChangeset(); - void SetInitialChangeset(int? changesetId); + int? GetFirstChangeset(); + void SetFirstChangeset(int? changesetId); bool ShouldSkip(string path); IGitTfsRemote InitBranch(RemoteOptions remoteOptions, string tfsRepositoryPath, int rootChangesetId = -1, bool fetchParentBranch = false, string gitBranchNameExpected = null, IRenameResult renameResult = null); string GetPathInGitRepo(string tfsPath);