I have been thinking about this, and to be precise, I think we need to make three assumptions in order for this to work:

1. All files in the shelveset need to come from the same TFS branch. This is, in reality, implied by using Git, as we couldn't possibly fetch a changeset that is split across branches, anyway.

2. The original files were all based off the same TFS "tip", meaning that, when we got the latest version from TFS we applied it to all files in the TFS branch, and not partially to some sub-folders, for example: To correctly account for this case we would need to check against the Git repo for all files that make up the shelveset and verify all of them were last changed in the same changeset, or by computing checksums. Anyway, this is a very rare scenario, but it probably makes sense to consider it.

3. The IDs that the Tfs API exposes in a shelveset are, in fact, those of the files when they were originally checked out plus one. This makes sense, since they are the original versions on the workspace plus "something" that is still not checked-in. What I don't know is if all supported TFS versions behave that way. I could only test with TFS 2008.

If all three assumptions are met, I think we would always compute the right BaseChangesetID this way. 

**Additionally, consider this example:**

    1.User gets latest for branch $/dev/  -> Latest changeset on the workspace is C7

    2.Checks out:
    $/dev/File1 at C5
    $/dev/File2 at C7
    ....
    3. Modifies File1 and File2
    ....
    4. Creates a shelveset which **only** contains $/dev/File1

    5. User 2 unshelves after fetcthing tfs/default:
          - Tfs API reports C6 as the id for the file
          - BaseChangesetId = 5
          - We find the git commit that corresponds to C5 (Note that the latest changeset
            from Tfs is C7)
          - A new commit is created with the contents of File2 and has C5 as its parent.


The result is that, even though we started work after updating to C7, from the shelveset we can only see what the base for **our changes** is. And so does TFS. If the commit was based on C7 instead, there wouldn't be any difference at all in the unshelved changes.

Uff, that was long :smile: