From d1c18c18c69900bb5e4ef8c7c856ecb61a554057 Mon Sep 17 00:00:00 2001 From: Andrij Abyzov Date: Wed, 13 Oct 2021 14:42:43 +0200 Subject: [PATCH] Fix a rare error fetching the workitems associated to a changeset In certain cases of legacy TFS projects using Changeset::WorkItems could cause a WorkItemTypeDeniedOrNotExistException (error TF201077) and cloning process stopped. This change uses AssociatedWorkItems instead which works fine even in this case. --- doc/release-notes/NEXT.md | 1 + src/GitTfs.Vs2015/TfsHelper.Vs2015.cs | 4 --- src/GitTfs.VsCommon/TfsHelper.Common.cs | 33 ++++----------------- src/GitTfs.VsCommon/TfsHelper.Vs2017Base.cs | 5 ---- 4 files changed, 6 insertions(+), 37 deletions(-) diff --git a/doc/release-notes/NEXT.md b/doc/release-notes/NEXT.md index 18ee53e99..3abe1a61b 100644 --- a/doc/release-notes/NEXT.md +++ b/doc/release-notes/NEXT.md @@ -1,2 +1,3 @@ * Keep already committed files (e.g. `.gitignore`) when cloning with `--changeset` (#1382 by @boogisha) * Correct WorkItem URL in the changeset metadata (#1396 by @siprbaum) +* Fix a rare error fetching the workitems associated to a changeset (#1395 @drolevar) diff --git a/src/GitTfs.Vs2015/TfsHelper.Vs2015.cs b/src/GitTfs.Vs2015/TfsHelper.Vs2015.cs index 5b9bac847..43ece787b 100644 --- a/src/GitTfs.Vs2015/TfsHelper.Vs2015.cs +++ b/src/GitTfs.Vs2015/TfsHelper.Vs2015.cs @@ -36,10 +36,6 @@ protected override string GetDialogAssemblyPath() return string.Empty; #endif } - protected override bool HasWorkItems(Changeset changeset) - { - return Retry.Do(() => changeset.AssociatedWorkItems.Length > 0); - } private string GetVsInstallDir() { diff --git a/src/GitTfs.VsCommon/TfsHelper.Common.cs b/src/GitTfs.VsCommon/TfsHelper.Common.cs index 7252bb144..d2aab1215 100644 --- a/src/GitTfs.VsCommon/TfsHelper.Common.cs +++ b/src/GitTfs.VsCommon/TfsHelper.Common.cs @@ -648,15 +648,12 @@ protected ITfsChangeset BuildTfsChangeset(Changeset changeset, IGitTfsRemote rem var tfsChangeset = _container.With(this).With(_bridge.Wrap(changeset)).GetInstance(); tfsChangeset.Summary = new TfsChangesetInfo { ChangesetId = changeset.ChangesetId, Remote = remote }; - if (HasWorkItems(changeset)) + tfsChangeset.Summary.Workitems = changeset.AssociatedWorkItems.Select(wi => new TfsWorkitem { - tfsChangeset.Summary.Workitems = changeset.WorkItems.Select(wi => new TfsWorkitem - { - Id = wi.Id, - Title = wi.Title, - Url = HyperlinkService.GetWorkItemEditorUrl(wi.Id).ToString() - }); - } + Id = wi.Id, + Title = wi.Title, + Url = HyperlinkService.GetWorkItemEditorUrl(wi.Id).ToString() + }); tfsChangeset.Summary.CheckinNotes = changeset.CheckinNote.Values.Select(note => new TfsCheckinNote { Name = note.Name, @@ -667,26 +664,6 @@ protected ITfsChangeset BuildTfsChangeset(Changeset changeset, IGitTfsRemote rem return tfsChangeset; } - protected virtual bool HasWorkItems(Changeset changeset) - { - // This method wraps changeset.WorkItems, because - // changeset.WorkItems might result to ConnectionException: TF26175: Team Foundation Core Services attribute 'AttachmentServerUrl' not found. - // in this case assume that it is initialized to null - // NB: in VS2011 a new property appeared (AssociatedWorkItems), which works correctly - WorkItem[] result = null; - try - { - result = Retry.Do(() => changeset.WorkItems); - } - catch (ConnectionException exception) - { - if (!exception.Message.StartsWith("TF26175:")) - throw; - } - - return result != null && result.Length > 0; - } - private readonly Dictionary _workspaces = new Dictionary(); public void WithWorkspace(string localDirectory, IGitTfsRemote remote, IEnumerable> mappings, TfsChangesetInfo versionToFetch, Action action) diff --git a/src/GitTfs.VsCommon/TfsHelper.Vs2017Base.cs b/src/GitTfs.VsCommon/TfsHelper.Vs2017Base.cs index 8f5b75427..14a795d21 100644 --- a/src/GitTfs.VsCommon/TfsHelper.Vs2017Base.cs +++ b/src/GitTfs.VsCommon/TfsHelper.Vs2017Base.cs @@ -112,11 +112,6 @@ private void LoadAssemblySearchPathFromVisualStudioPrivateRegistry(string devenv myAssemblySearchPaths.Add(Path.Combine(myVisualStudioInstallationPath, myTeamExplorerFolder)); } - protected override bool HasWorkItems(Changeset changeset) - { - return Retry.Do(() => changeset.AssociatedWorkItems.Length > 0); - } - /// /// Enumerates the list of installed VS instances and returns the first one /// matching . Right now there is no way for the user to influence