Alex Gordon
Alex Gordon

Reputation: 60691

Ignoring files from checkin with certain pattern of change

Since having started using JetBrains Annotations, for my own benefit I've decorated all methods with [CanBeNull] or [NotNull]

For example, the following line:

public AccountController(IAccountService accountService)

Would be changed to:

    public AccountController([CanBeNull] IAccountService accountService)

Another example would be:

public Account CreateAccountEntity(Account accountEnttity)

would be changed to:

    [CanBeNull]
    public Account CreateAccountEntity([NotNull] Account accountEnttity)

How can I bypass pending changes for annotations, specifically "[CanBeNull]", and have TFS completely ignore this change?

Upvotes: 27

Views: 793

Answers (5)

Andrii Litvinov
Andrii Litvinov

Reputation: 13182

If your main goal is to write better code with the help of ReSharper telling you whether you should expect nulls or not or produce other warnings and you don't want to disturb other team members with it I would suggest you to consider using External Annotations instead of annotation attributes in code.

You can then decide whether you want to commit those files or keep them locally. And even if you commit your code will still be clean without those extra attributes.

At least I would give it a try.

Upvotes: 1

Vasyl Zvarydchuk
Vasyl Zvarydchuk

Reputation: 3839

I agree with other answers that such kind of feature isn’t officially supported by Microsoft.

But you can also overwrite TFVC in a few ways if it is really needed. You can write your own Visual Studio plug-in or Source Control VSPackage .

Upvotes: 5

AL - Lil Hunk
AL - Lil Hunk

Reputation: 1015

In short, you shouldn't, the closest feature is the tfignore, but this will ignore all file.

On the other hand, if you really want this, you could create a tool using the TFS API, and you would have to run this before check-ins and it would verify all the pending files in your solution and looking for this small changes and excluding the files, but this could cause the problem that at some point you may make a change to an excluded file and it won't get checked in and cause problems. You would need to add extra code to verify what files should be included from the excluded list.

External tool used inside VS Here you can see how to add tools to the Tools menu and send arguments to it.

TFS API Example This example shows how to use the TFS API. There is a 'workspace.AddIgnoreFileExclusion()', but I don't have TFS here, so I'll verify how to ignore the files later.

Now in my experience, the only reason I wouldn't want to check in those changes would be to avoid conflicts with the team. If I see a lot of value in some practice like using the annotations, I would talk with the team to get them to buy in into the idea of using annotations, that way everyone would be using it and soon every file will have the annotations and there won't be any conflicts.

Upvotes: 7

slugster
slugster

Reputation: 49974

You cannot make TFS "ignore" the change. That is the purpose of TFS - to track all changes.

The way I interpret your question, you are wanting to avoid the noise of potentially many small but innocuous checkins due to your annotations. If this is correct then there is a way to use TFS that will minimize the noise:

  • create a branch from where you are currently working (let's call it "BranchA"), then make all the annotation changes in that new branch ("BranchB"), checking them in regularly
  • if this is going to take some time (days, weeks) to complete then ensure you do regular merges from BranchA to BranchB
  • when you think you've finished do a final merge from BranchA to BranchB. If you've pulled across any new methods then ensure you annotate them. Repeat this step if you made changes.
  • merge all changes from BranchB back to BranchA. This will have the effect of aggregating all your smaller changes into a single large checkin/changeset in BranchA. Provided you have been doing regular merges from BranchA to BranchB this should be problem free even if considerable time has passed since you started the decoration work.

Upvotes: 23

Daniel Mann
Daniel Mann

Reputation: 58980

You can't selectively ignore changes within files, in TFVC or in any other SCM I've ever encountered.

Upvotes: 6

Related Questions