简体   繁体   中英

Find out the source control state of a ProjectItem from a Visual Studio extension

I'm currently developing a Visual Studio extension. For a new feature I need to find out whether a given ProjectItem (file) was modified (has "Pending Changes" since the last commit). For this I would like to query the source control provider.

  • I already tried searching all the properties of the ProjectItem but there is nothing hidden in there.
  • I also tried getting a service associated with source control from the Package.cs. I tried getting IVsSccManager2, IVsSccManager3 and IVsSccGlyphs. All return null (the test project is under source control). edit: I try to get these services by calling GetService(typeof(IVsSccManager2)) inside my Package.cs . The source control plugin of my debugging session correctly shows the changed files at the time this is called.

I can't seem to find anything online about this topic. How can I find out the modified state? Is it even possible?

After letting this topic sit for some time I recently came back to it and found the solution thanks to the help of my collegue. The problem was that I had no experience in bitwise comparison so I didn't know how to handle the response properly. Luckily my collegue gave me the right tip.

To interpret the result of status (thanks to @simon-mourier for the help on this code):

uint[] sccStatus = new uint[] { 0 };
if (VSConstants.S_OK == manager.GetSccGlyph(1, new[] { filePath }, new[] { VsStateIcon.STATEICON_NOSTATEICON }, sccStatus))
{
    __SccStatus status = (__SccStatus)sccStatus[0];
}

One has to do bitwise comparison with the state of __SccStatus you are looking for, for example:

if ((sccStatus[0] & (uint)__SccStatus.SCC_STATUS_RESERVED_2) != 0)
    return true;

The comparison returns true in case the state is set. If you need help on what specific state combinations can mean, just comment here and I can help on that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM