我找不到一种无缝的方式来完成您正在寻找的东西,但我确实找到了一个可能适合您需求的选项,考虑到这只是您当地人想要的东西机器。
可以手动调用 TortoiseSVN 提交对话框,为其提供路径以搜索要提交的文件,如下所示:
C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe /command:commit /pathfile:"<a file containing paths>"
因此,既然您知道要忽略哪些目录和文件,您可以提供一个仅包含您希望提交的目录和文件的路径文件。
请记住,路径文件必须采用 UTF-16(小端序)编码,没有 BOM。路径由换行符分隔。您可以创建这样一个有效的路径文件(在 C# 中),如下所示:
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);
在我对路径的实验中,支持目录和文件路径,但不支持通配符,因此在生成路径文件时需要进行任何过滤。
TortoiseProc /command:commit 有几个额外的命令行选项,您可以找到 here。
同样的方法也适用于“检查修改”,用/command:repostatus 代替/command:commit。总结:
- 创建一个抓取所有感兴趣的文件名的脚本
- 过滤掉所有不感兴趣的文件名(可能来自您机器上某处的“忽略文件”)。
- 以 UTF-16 LE 格式(无 BOM)写入文件列表。
- 调用 TortoiseProc 并使用
/pathfile 参数指定文件列表和 /command 转发或提交。
- (可选)删除文件列表。
可选 - 使用钩子脚本与“提交”集成
顺便说一句,通过使用设置中的 TortoiseSVN 挂钩脚本选项,我确实找到了一种“集成”路径。它仍然使用上面的 TortoiseProc 过程,但另外提供了一种仍然使用 TortoiseSVN 提交上下文菜单的方法(有一个怪癖)。
钩子脚本使用的特定语言并不重要,重要的是它能够处理命令行参数并返回退出代码。来自文档(here):
这可以是批处理文件、可执行文件或任何其他文件
它具有有效的 Windows 文件关联,例如perl 脚本。
对于这个例子,我使用了 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;
}
为简洁起见,ParentProcessUtilities.GetParentProcess,我在另一个 SO 帖子中使用,可以找到 here。
说明:
PATH 输入参数指向一个临时文件,该文件包含在资源管理器中选择的所有目录和文件。由此,您可以构建所需路径的列表。构建列表并将其写入文件后,我们重新启动 TortoiseProc,将新文件作为参数以及可用于跟踪的专有参数传递。
最后,我们返回一个非 0 的退出代码,这会阻止原始 TortoiseSVN 提交窗口出现,但要注意一点。将出现一个“错误”对话框,显示写入 stderr 的消息;我所说的怪癖。该代码最重要的部分之一是在实际执行所有这些工作之前检查父进程的专有参数。这个检查可以防止 hook 无限次运行,因为当 TortoiseProc 被上面的代码重新启动时,hook 脚本会被再次触发,然后再次调用这个代码。
我还研究了最初传入的 PATH 文件的内容是否可以就地更改,但不能。不幸的是,这只是 TortoiseSVN 为钩子脚本而显式输出的文件,然后将其删除。也许这可能是未来的功能。