Skip to content

Conversation

larsxschneider
Copy link
Contributor

I am working with a TFS repo that I don't have full access to. I am not interested in the parts that I don't have access to and I just want git-tfs to ignore these parts. Therefore, I implemented this very basic workaround here. I wonder what you think about the approach? Do you see problems with it? Would that be something you would be willing to merge? Maybe I could mask the workaround behind an option --ignore-restricted-content or something?

See also #1033

{
// Ignore exceptions "TF14098: Access Denied: User ??? needs
// Read permission(s) for at least one item in changeset ???."
if (!ex.Message.Contains("TF14098"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nicer to check for the exact exception here: Microsoft.TeamFoundation.VersionControl.Client.ResourceAccessException. However, then I would need to include the Microsoft namespace here and I have the impression that would interfere the separation of concerns in the git-tfs project, no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, then I would need to include the Microsoft namespace here and I have the impression that would interfere the separation of concerns in the git-tfs project, no?

Right, GitTfs/Core shouldn't be able to see anything in the Microsoft.TeamFoundation namespace, though it's mostly related to packaging/versioning rather than separation of concerns. If the class is consistent, it'd be ok to do something like ex.GetType().FullName == "Microsoft.TeamFoundation.VersionControl.Client.ResourceAccessException", though my preference is to stick with the check for TF14098 in the exception message.

@spraints
Copy link
Member

I wonder what you think about the approach? Do you see problems with it? Would that be something you would be willing to merge? Maybe I could mask the workaround behind an option --ignore-restricted-content or something?

I think this is a good change. I haven't had a chance to look through the code yet. I think that putting the workaround behind an option makes sense, and maybe also suggest using it if the error happens?

throw;
}

Trace.WriteLine("Quick fetch failed: " + ex.Message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, would there end up being any contents in the repo? If not, maybe it doesn't make sense to catch for quick-clone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that no contents would be in the repo in case of quick-clone. However, it looks like as if QuickFetch is also called within a full fetch for the very first change set:

remote.QuickFetch(InitialChangeset.Value);

Do you see an easy way to distinguish the two cases?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right, I forgot about that. It'd still be good to make quick-clone fail, but not at the expense of breaking full clones or fetches. So, if it's not too cumbersome to separate the behavior of the two cases, please do.

{
throw;
}
Trace.WriteLine("No commit found commit changeset " + rootChangesetId + ": " + ex.Message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this return null, since sha1RootCommit will be null, and it looks like this method returns early if it's unable to set sha1RootCommit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. Yeah, I will try that and update the PR!

@larsxschneider
Copy link
Contributor Author

@spraints I assume you would prefer it if this new behaviour would be tested somehow. Can you give me some pointers how I could approach that? For example an existing test case that is similar that I should study or maybe an existing test case that throws an exception like the one I am catching here?

@spraints
Copy link
Member

I assume you would prefer it if this new behaviour would be tested somehow. Can you give me some pointers how I could approach that? For example an existing test case that is similar that I should study or maybe an existing test case that throws an exception like the one I am catching here?

Yeah, tests would be great. I think an integration test would make the most sense. Here's an example of a test of git tfs clone:

https://github.com/git-tfs/git-tfs/blob/master/src/GitTfsTest/Integration/CloneTests.cs#L42-L61

You'll need to extend the TFS test double so that it can throw an error for a particular changeset instead of returning. Does that work as a starting point?

@larsxschneider
Copy link
Contributor Author

I haven't forgotten about this. I found a few more issues and my Windows box is still working on the migration. I'll get back to it as soon as all my TFS content is in Git (hopefully in a week or two).

@pmiossec
Copy link
Member

@larsxschneider Any update on that?

@larsxschneider
Copy link
Contributor Author

Uhh. Thanks for the reminder @pmiossec ! What do you think of the current implementation? Would that be acceptable already? I wanted to create a test case but I didn't know how to mock the access management.

}

public void QuickFetch(int changesetId)
public void QuickFetch(int changesetId, bool ignoreRestricted, bool printRestrictionHint)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this refactoring OK? If yes, then I could make it an independent commit before the --ignore-restricted-changeset commit.

If a TFS user has no read access to a changeset, then TFS responds with
a "TF14098: Access Denied" error. This error aborts the fetch operation.

Add the --ignore-restricted-changesets option which allows the user to
ignore these respective changeset. If the option is set, then git tfs
will import the access restricted changeset as empty commit and ignore
the error.
Copy link
Member

@spraints spraints left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks @larsxschneider!

@spraints spraints merged commit cdd12b7 into git-tfs:master May 29, 2018
@larsxschneider larsxschneider deleted the ls/handle-access branch May 30, 2018 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants