Fix missing merge parent

This pull request fixes issue #627 (and also #590,of which it is a duplicate).

In some cases (probably involving a badly formed TFS changeset, or  a merge changeset in which the merge parent has been deleted), the VersionControl.QueryMerges call in FindMergeChangesetParent can return an empty array.  In such cases, the subsequent merginfo.Max(x => x.SourceVersion) call will throw a "Sequence contains no objects" InvalidOperationException.

This patch avoids that error by checking for a zero-length array, and returning -1 to the caller, which then checks for that and handles it with a warning message that git-tfs can't locate the parent.
Thanks.  I wasn’t sure how things worked and what should be returned, but returning an error indication and then testing for it seemed like a sure cure.  But I like your method better.

 

From: gfody [mailto:notifications@github.com] 
Sent: Sunday, July 13, 2014 4:54 AM
To: git-tfs/git-tfs
Cc: Dave Hanna
Subject: Re: [git-tfs] Fix missing merge parent (#628)

 

In GitTfs.VsCommon/TfsHelper.Common.cs:

> @@ -133,6 +133,7 @@ public virtual int FindMergeChangesetParent(string path, long targetChangeset, G
>          {
>              var targetVersion = new ChangesetVersionSpec((int)targetChangeset);
>              var mergeInfo = VersionControl.QueryMerges(null, null, path, targetVersion, targetVersion, targetVersion, RecursionType.Full);
> +            if (mergeInfo.Length == 0) return -1;

technically you should just return targetChangeset. the subsequent FindCommitByChangesetId will not find any and fall through accordingly. the real fix is avoiding the empty mergeInfo.Max(...)

—
Reply to this email directly or view it on GitHub <https://github.com/git-tfs/git-tfs/pull/628/files#r14857580> .  <https://github.com/notifications/beacon/1838609__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcyMDg2NDQ1NSwiZGF0YSI6eyJpZCI6MzU4NDk3NDN9fQ==--c4a8281e0f9ffce384c938221cbdc2b296d5af98.gif>