svn:忽略生成的子文件夹

发布于 2024-09-19 18:46:11 字数 625 浏览 11 评论 0原文

我总是在使用 svn:ignore 时遇到麻烦,但这次我想我可能正在尝试一些不可能的事情。

假设 dir 结构:

/
   /foo
   /bar
   /web
      /uploads
          /assets
          /avatars
              /fu
                  /*.jpg
              /ba
                  /*.jpg
              keepme.jpg
              keepmetoo.jpg

我想忽略 avatars 目录的所有子文件夹,但不忽略该目录的文件(keepme.jpg、keepmetoo.jpg)。

avatar 子文件夹(fu、ba)是自动生成的,并且名称无法预先确定,因此需要完全忽略所有 /avatar 子文件夹。

这可能吗?又如何呢?

编辑我们不希望使用提交后挂钩。这只是一个偏好问题。我们有很多完善的应用程序,并开发了标准化的处理方式,但提交后挂钩尚未得到利用。我们只是不想添加任何不必要的额外移动部件。坦率地说,在考虑添加提交后挂钩之前,我们更有可能解决目录结构(这不是一项小任务)。

I'm always having troubles with svn:ignore, but this time I think I may be attempting something impossible.

assuming dir structure:

/
   /foo
   /bar
   /web
      /uploads
          /assets
          /avatars
              /fu
                  /*.jpg
              /ba
                  /*.jpg
              keepme.jpg
              keepmetoo.jpg

I want to be ignore all subfolders of the avatars directory but not the files of that directory (keepme.jpg, keepmetoo.jpg).

The avatar subfolders (fu, ba) are auto generated and the names cannot be predetermined, so need to completely ignore all /avatar subfolders.

Is this possible? and how?

Edit we would prefer not to use post-commit hooks. This is simply a matter of preference. We have a lot of well established applications and have developed a standardised way of doing things and post commit hooks simply haven't been utilized yet. We would simple prefer not to add any unnecessary additional moving parts. Frankly it is more likely we would address the directory structure (which is no small task) before considering adding post-commit hooks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

扛刀软妹 2024-09-26 18:46:19

设置 start-commit hook 可能是一个解决方案。

Setting up a start-commit hook could be a solution.

彻夜缠绵 2024-09-26 18:46:18

简而言之,对于仅配置的纯 SVN,这是不可能的。但是您可以选择一些选项来设置这些属性并检查它们,例如

  • 增强头像自动生成工具、
  • 在自动生成后调用更新 SVN 设置的批处理文件、
  • 在提交之前调用更新 SVN 设置的批处理文件。

在服务器端,

  • 如果提交前不遵守规则,您可以拒绝提交,
  • 自动更新提交后挂钩上的设置,
  • 或者需要聪明的开发人员只在 CI 系统中签入。

首先,我建议在自动生成文件夹后自动更新 svn:ignore 属性。最简单的方法是在生成后调用批处理文件。批处理文件本身很简单:

@echo off
echo.>~svnignore
dir /b /aD >~svnignore
svn propset svn:ignore --file ~svnignore .
del ~svnignore

当然,文件 ~svnignore 应该是一个您可以保证不会用于其他任何用途的文件名。如果这是在生成时自动调用的,那么这应该对每个人都有效。

其次,我建议在预提交挂钩中检查完整性。在提交后进行可能还可以,但在持续集成系统中进行肯定就太晚了。

最后,您还有另一个选择,但我不建议您走这条路:当您用 tortoisesvn 标记问题时,我假设您使用了这个工具。这为您提供了使用客户端预提交挂钩的附加选项。为此,请进入 TortoiseSVN 设置对话框。在左侧树中,您将找到一个条目“Hook Scripts”,您可以在其中配置一些可执行文件(例如批处理文件...)在特定时间执行,例如在“pre-”时执行。提交时间。

这样做的缺点是你实际上破坏了 SVN 的所有控制台使用,并且如果你想对某些构建/标签等进行一些自动化,那么这将毫无价值。

In short, with config-only pure SVN this is not possible. But you have some options for settings those properties, and for checking them, like

  • beefing up your avatar auto-generation tool,
  • invoke a batch file updating SVN settings after the auto-generation,
  • invoke a batch file updating SVN settings before the commit.

On the server side, you can

  • reject commits on pre-commit if they do not follow the rules,
  • automatically update the settings on the post-commit hook,
  • or require smart developers and only check in the CI system.

First, I would recommend to automatically update the svn:ignore property after the auto-generation of the folders. The easiest way would be to invoke a batch-file after doing the generation. The batch-file itself would be simple:

@echo off
echo.>~svnignore
dir /b /aD >~svnignore
svn propset svn:ignore --file ~svnignore .
del ~svnignore

Of course, the file ~svnignore should be a filename which you can guarantee to not use for anything else. If this is invoked automatically upon the generation, this should work for everybody.

Second, I would recommend to check for the integrity either in the pre-commit hook. Doing it in the post-commit may be acceptable, doing it in the continuous integration system will definitely be too late.

Finally, you have another option, though I would not recommend going this route: As you tagged the question with tortoisesvn I assume, you use this tool. This provides you with the additional option to use a client-side pre-commit hook. For this, go into the TortoiseSVN Settings dialog. In the left-side tree you will find an entry Hook Scripts, where you can configure some executables (like batch-files...) to be executed upon certain times, like at pre-commit time.

The disadvantage of this is that you practically break all console usage of SVN, and if you want to have some automation for some builds/tags etc., this will be worthless.

我不在是我 2024-09-26 18:46:16

你想将整个批次存储在 svn 中,除了 /avataurs/fu 和 avatars/ba(实际上是所有 avatars/xxx)?

您需要首先将剩余的目录结构添加到 svn。使用Tortoise添加根目录,取消选中不想添加的目录,然后提交。这解决了最初的问题 - 不提交有问题的子目录,一切都很好。

除此之外,下一个问题是您不希望其他人“意外”添加新生成的子目录 - 在这种情况下,预提交挂钩至关重要。它们确实非常简单 - 您只需要编写一个快速批处理文件或 perl 脚本,在传入文件的路径上执行正则表达式,如果有包含 ".*/avatars/.*/.*" 则返回 1 (仍然允许将新文件添加到该目录)。该挂钩还可以返回将显示给添加文件的用户的文本。我使用它来防止使用禁止列表上的文件扩展名(例如 .obj 等)签入文件。

如果头像子目录从未进入 SVN,那么你将永远不会检查它们 - 显然 - 你的工作就完成了!


这是我的 pre-commit.cmd 挂钩文件的副本。只需将其放入您的 hooks 目录(在 Windows 上)即可。

@echo off

svnlook changed -t %2 %1 > c:\temp\pre-commit.txt

findstr /G:"%1\hooks\ignore-matches.txt"  c:\temp\pre-commit.txt > c:\temp\precommit-bad.txt
if %ERRORLEVEL% NEQ 0 exit 0

echo disallowed file extension >> c:\temp\precommit-bad.txt

type c:\temp\precommit-bad.txt 1>&2
exit 1

ignore-matches.txt 文件包含这样的行:

^[^D].*\.obj$

任何与ignore-matches.txt 文件中的条目匹配的内容都意味着提交被拒绝,用户将不得不重试,这次正确。

You want to store the entire lot in svn, except /avataurs/fu and avatars/ba (all avatars/xxx in fact)?

You need to initially add the remaining directory structure to svn. Use Tortoise to add the root directory, un-check the directories you do not want to add, then commit. that solves the initial problem - of not committing the offending subdirectories, all's good.

Except, the next problem is that you do not want anyone else to 'accidentally' add newly generated subdirectories - in this case, a pre-commit hook is essential. They are very simple indeed - you only need to write a quick batch file or perl script that does aregex on the paths of the incoming files, and return 1 if any contain ".*/avatars/.*/.*" (which will still allow new files to be added to that directory). The hook can also return text that will be displayed to the user who was adding the files. I use one to prevent files being checked in with a file extension on a ban list (eg .obj etc).

If the avatar subdirs never make it into SVN then you'll never check them out - obviously - and your job is done!


Here's a copy of my pre-commit.cmd hook file. Just drop it into your hooks directory (on windows) and you're good to go.

@echo off

svnlook changed -t %2 %1 > c:\temp\pre-commit.txt

findstr /G:"%1\hooks\ignore-matches.txt"  c:\temp\pre-commit.txt > c:\temp\precommit-bad.txt
if %ERRORLEVEL% NEQ 0 exit 0

echo disallowed file extension >> c:\temp\precommit-bad.txt

type c:\temp\precommit-bad.txt 1>&2
exit 1

the ignore-matches.txt file contains lines like this:

^[^D].*\.obj$

anything that matches the entries in the ignore-matches.txt file means the commit is rejected,the user will have to try again, correctly this time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文