NArrange on check-in

If you are having a problem using Fortress, post a message here.

Moderator: SourceGear

Post Reply
everpresent
Posts: 1
Joined: Tue Apr 06, 2010 8:53 am

NArrange on check-in

Post by everpresent » Tue Apr 06, 2010 9:01 am

Is there any way that I can force a tool, like NArrange, to run during the pre-checkin process (or other validation apps for that matter like StyleCop). Subversion had hooks for pre-checkin and post-checkin and I'm sure that Fortress has something similar I just can't seem to find where the tie-in is. I've got CC.NET setup to run my post-build tools (like FxCop, NUnit, and NCover) but I would like a way to modify a file being checked in or to reject a check in based on a file not following coding standards. Can anyone point me in the right direction?

Regards

Beth
Posts: 8550
Joined: Wed Jun 21, 2006 8:24 pm
Location: SourceGear
Contact:

Re: NArrange on check-in

Post by Beth » Tue Apr 06, 2010 10:08 am

We don't currently have that functionality. I can take a feature request if you'd like.

In the meantime what one could do is either use the client API to create a small tool for check-ins that could run the tool you want as well, or write a script with the command-line that would be used for check-ins, but kick off the second tool before actually performing the check-in.

F: 15382
Beth Kieler
SourceGear Technical Support

jseidell
Posts: 14
Joined: Mon May 19, 2008 4:12 pm

Re: NArrange on check-in

Post by jseidell » Fri May 07, 2010 11:03 am

I would like to add we also would be very interested in having this functionality. I would find it especially helpful because NArrange would maintain a controlled order of the code, which allows a better blame history of what actually changed, was added and removed, as opposed to just moving functions around during refactoring. Please notify us if this will become an item and if so when it will be released.

Thanks,

Jason Seidell
Infinedi

Beth
Posts: 8550
Joined: Wed Jun 21, 2006 8:24 pm
Location: SourceGear
Contact:

Re: NArrange on check-in

Post by Beth » Fri May 07, 2010 12:13 pm

Your vote has been added.

Thanks.
Beth Kieler
SourceGear Technical Support

jseidell
Posts: 14
Joined: Mon May 19, 2008 4:12 pm

Re: NArrange on check-in

Post by jseidell » Tue Apr 26, 2011 2:42 pm

Just as a follow up I did find a work around. In Visual Studio you can write macros that automatically fire when IDE events happen.

To create a macro to automatically NArrange everytime a file is saved.
1) Go to 'Tools' -> 'Macros' -> 'Macros IDE ...'
2) From the macro IDE editor Select 'MyMacros' and open the 'EnvironmentEvents'
3) Select the 'DocumentEvents' and 'DocumentSaved' event to generate custom code for the IDE document save event.
4) Insert code to run NArrange against the currently saved file:

Code: Select all

Const NarrangeExePath As String = "C:\Program Files (x86)\NArrange 0.2.8\narrange-console.exe"
Const NarrangeArgs As String = """/c:R:\ediexe\NArrangeConfig.xml"" {0}"

Shell(NarrangeExePath & " " & String.Format(NarrangeArgs, Document.FullName), AppWinStyle.NormalFocus, True, 1000)
Obviously change the paths above to your machine, environment, and config file path.

Ideally I would rather pull the NArrange executable path and arguments from the registry that way we can script updating the paths across all development machines, but for right now this gets it up and running. The /c option tells NArrange to use a common configuration file that our senior programmers maintain so all the developers are NArranging to the same standard.
5) Save the changes and close the MacroIDE, restart Visual Studio and you should be good to go. I have it setup to show me the NArrange console window so I know it's working and to wait until NArrange completes or 1 second per file. Since I just started doing this I'm not sure if this will be a pain or annoyance, but I want to see it working at least for now.
6) I changed the Visual Studio options to 'Auto-load changes, if saved' (under Options -> Environment -> Documents) so it will automatically reload if NArrange updated the file instead of prompting me for the change.

I tested with Fortress, creating new files, and doing a check-in before saving and didn't really encounter any problems, except if I modify a file then undo check out, and then modify the file again Visual Studio sometimes misses the change to the file on disk and prompts whether to keep your changes or reload the file from disk. If you get this pop-up and don't pay attention and click to reload from disk you will lose whatever change you just made, however since this pops up as soon as you make the first change to the file you will only lose a few keystrokes when it reloads.

Ideally I would still rather see this as an option on the Fortress/Vault server so I don't have to make sure all the developers are running this setup and pointing to the correct config file, etc. to maintain diff consitency of our files and showing true code changes, not just refactoring and moving code around.

Hope someone else finds this handy.

Jason

Link to MSDN documentation for IDE Events that macros can tie to: http://msdn.microsoft.com/en-us/library ... s.80).aspx

Beth
Posts: 8550
Joined: Wed Jun 21, 2006 8:24 pm
Location: SourceGear
Contact:

Re: NArrange on check-in

Post by Beth » Tue Apr 26, 2011 3:19 pm

Thank you for the update. Posting the information is appreciated.
Beth Kieler
SourceGear Technical Support

Post Reply