Ignore specific directories or files without using svn: ignore

For some reason, no one has ever set decent svn:ignore properties in our repository, and when I asked about it, the answer was "no one complained about this before, can you just leave the" unversioned items "unchecked?" (We pretty much use TortoiseSVN).

I am new to the team, so I want to set up some local ignore lists instead of making changes to the repository perforce.

I know about the global ignore list, but the global ignore list does not accept specific paths , but only simple, single-level file templates. I read the question about the local ignore list , but this question does not really ask about “ignoring” unversioned files, but actually asks about blocking the commit of certain version files. I read another question about ignoring the local directory as I want, but the accepted answer to this question uses a global ignore list, which does not work for me due to not specifying specific paths in my working copy.

I can set some svn:ignore properties locally, but directories cannot be added to change lists (as recommended in the question above to avoid compiling file versions), so I risk accidentally making these changes.

Is there a way to locally ignore certain unversioned directories or files in my working copy tree without using svn:ignore ?


Update: The current top answer brings me very close to what I want. This allows me to filter out arbitrary files in the "check for changes" or "commit" dialog box. However, if I want to include directory changes (i.e., Changes in the properties of the directory version), then TortoiseSVN will also include all files in the directory automatically (i.e. I cannot both list the directory and filter files in the directory).

+8
svn tortoisesvn
source share
1 answer

I could not find an easy way to accomplish what you are looking for, but I found an option that can satisfy your needs, given that this is what you want only for your local machine.

You can manually open the TortoiseSVN Commit dialog, providing paths to search for files to commit, for example:

 C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe /command:commit /pathfile:"<a file containing paths>" 

So, since you know which directories and files you want to ignore, you can provide a path file that contains only those directories and files that you want to commit.

Keep in mind that the path file must be in UTF-16 (little-endian) encoding without specification. Paths are separated by new string characters. You can create a file of valid paths (in C #), for example:

 string[] paths = { @"c:\code\1\dir1", @"c:\code\1\dir2", @"c:\code\1\dir3\file1.txt" }; UnicodeEncoding encoding = new UnicodeEncoding(false, false); System.IO.File.WriteAllText(@"C:\temp\pathslist.txt", string.Join("\n", paths), encoding); 

In my experiments with paths, both directory paths and file paths are supported, but not wildcards, so any filtering should be done when the paths file is created.

There are a couple of additional command line options for TortoiseProc /command:commit , which you can find here .

The same method will work for Check for Changes, replacing /command:repostatus with /command:commit . In short:

  • Create a script that captures all the file names of interest
  • Filter out all file names that are not interesting (perhaps from the file "ignore" somewhere on your computer).
  • Enter the list of files in UTF-16 LE format (without specification).
  • Call TortoiseProc with the /pathfile argument specifying a list of files and /command either repostatus or commit.
  • Optionally, delete the file list.

Not necessary. Integration with Commit with hook script

As an aside, I found one way to “integrate” using the TortoiseSVN Hook script options in the settings. It still uses the TortoiseProc procedure described above, but additionally provides the ability to use the TortoiseSVN Commit context menu (with one quirk).

The specific language you use for the hook script is not important, only so that it can process command line arguments and return an exit code. From the documentation ( here ):

It can be a batch file, an executable file or any other file that has a valid Windows file association, for example. perl script.

In this example, I used C #:

 static void Main(string[] args) { // Process the three command-line arguments string PATH = args[0] , MESSAGEFILE = args[1] , CWD = args[2]; const string tortoiseProcPath = @"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe"; const string someArgForOurUse = @"/2E040D90-E3AD-4AC5-AA46-E6D9F1034E55"; const string wantedPathsFile = @"C:\temp\svn_paths_list.txt"; //System.Diagnostics.Debugger.Launch(); System.Diagnostics.Process parentProc = ParentProcessUtilities.GetParentProcess(); // If the parent process isn't what is expected or it has the proprietary argument then exit. if ((parentProc == null) || (!parentProc.MainModule.FileName.Equals(tortoiseProcPath, StringComparison.InvariantCultureIgnoreCase)) || GetProcessCommandLine(parentProc.Id).Contains(someArgForOurUse)) return; // Read all selected path from passed-in the temp file // Each line contains a file/directory selected in Explorer string[] fileLines = System.IO.File.ReadAllLines(PATH); IEnumerable<string> wantedPaths = GetWantedPaths(fileLines); UnicodeEncoding encoding = new UnicodeEncoding(false, false); System.IO.File.WriteAllText(wantedPathsFile, string.Join("\n", wantedPaths), encoding); System.Diagnostics.Process.Start(tortoiseProcPath, "/command:commit /pathfile:\"" + wantedPathsFile + "\" " + someArgForOurUse); Console.Error.WriteLine("Don't worry. Everything will be ok."); Environment.Exit(1); } private static IEnumerable<string> GetWantedPaths(string[] selectedPaths) { // Do whatever you want here to filter directories and files return selectedPaths; } // Add System.Management reference private static string GetProcessCommandLine(int processId) { System.Management.SelectQuery wmiQuery = new System.Management.SelectQuery("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + processId.ToString()); System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(wmiQuery); foreach (System.Management.ManagementObject obj in searcher.Get()) return obj["CommandLine"].ToString(); return null; } 

For brevity, ParentProcessUtilities.GetParentProcess , which I used from another SO post, can be found here .

Explanation:

The PATH input argument points to a temporary file containing all the directories and files selected in Explorer. From this you can create a list of desired paths. When the list is created and written to the file, we then restart TortoiseProc, pass the new file as an argument, as well as a proprietary argument that can be used for tracking.

At the end, we return an exit code other than 0, which prevents the original TortoiseSVN Commit window from appearing with one caveat. The Error dialog box appears, displaying the message recorded in stderr; which I talked about. One of the most important parts of this code is to check the parent process for a proprietary argument before doing all this work. This check prevents an infinite number of hook attempts, because when TortoiseProc is overwritten with the above code, the script hook will be run again and subsequently call that code again.

I also examined if the modified source PATH file can be modified, but it cannot. Unfortunately, this is just a file that TortoiseSVN explicitly outputs with a hook script purpose and then deletes it. Perhaps this may be a future feature.

+5
source share

All Articles