Board logo

标题: [文件操作] 批处理怎样实现前缀不带有指定字符串不能提交? [打印本页]

作者: 潘多拉    时间: 2014-11-27 11:25     标题: 批处理怎样实现前缀不带有指定字符串不能提交?

  1. setlocal  
  2. set svnlook="F:\Program Files (x86)\VisualSVN Server\bin\svnlook.exe"  
  3. set REPOS=%1  
  4. set TXN=%2
  5. rem 过滤文件类型
  6. %svnlook% changed -t %TXN% %REPOS%|findstr /I "txt$"
  7. if %errorlevel% EQU 0 (goto err1)
  8. :ok
  9. exit 0
  10. :err1
  11. echo. >&2
  12. echo 错误:禁止提交前缀名错误的文件 ... >&2
  13. exit 1
复制代码
我想实现一个功能:(前缀)在开始不带有 FIMS- 的文件不能提交    可是我这个批处理只能实现以txt为后缀的不能提交  我该怎么改 请大拿给点建议
作者: DAIC    时间: 2014-11-27 16:16

%svnlook% changed -t %TXN% %REPOS%|findstr /I "^FIMS-"
作者: 潘多拉    时间: 2014-11-27 17:01

回复 2# DAIC


    亲 我试过了 这样不行,我不知道为什么,用XX$或者写死了一个文件名就可以做限制 ,就是不能控制前缀   。。。
作者: DAIC    时间: 2014-11-27 17:06

回复 3# 潘多拉


    %svnlook% changed -t %TXN% %REPOS% 把这个命令的结果发出来看看
作者: 潘多拉    时间: 2014-11-27 19:07

回复 4# DAIC


    >>a.txt 导出的都是空值、大神还有什么办法能导出???
作者: apang    时间: 2014-11-27 20:57

这样试下呢?
findstr /I "^FIMS\-.*txt$"
作者: DAIC    时间: 2014-11-27 21:30

回复 5# 潘多拉


    >a.txt 2>&1 试试
作者: 潘多拉    时间: 2014-11-28 08:44

回复 7# DAIC


    谢谢两位帮忙,还是不行,搞不明白为什么写成定值或后缀就没有问题,我去把svn的提交检查机制看一下,再写吧,再次感谢!!
作者: DAIC    时间: 2014-11-28 08:56

回复 8# 潘多拉


    在你顶楼的 %svnlook% changed -t %TXN% %REPOS% 这行命令后面不要加任何管道和重定向,能看到这条命令执行的结果吗?
作者: 潘多拉    时间: 2014-11-28 10:26

回复 9# DAIC
javascript:;

    看不到,它直接调用svnlook 但是具体怎么调用没有显示
作者: DAIC    时间: 2014-11-28 10:50

回复 10# 潘多拉


set REPOS=%1
set TXN=%2
看起来是%1和%2这两个参数没有获取到
作者: 潘多拉    时间: 2014-11-28 11:40

回复 11# DAIC

    可能你不清楚这句话的意思,    %svnlook% changed -t %txn% %repos%,获得未提交的事务中有什么改变,打印到标准输出  ,这可以说是svn给出的一个钩子文件的模板(用于在提交之前做限制)我附上一个解释文档。
  1. #!/bin/sh
  2. # PRE-COMMIT HOOK
  3. #
  4. # The pre-commit hook is invoked before a Subversion txn is
  5. # committed.  Subversion runs this hook by invoking a program
  6. # (script, executable, binary, etc.) named 'pre-commit' (for which
  7. # this file is a template), with the following ordered arguments:
  8. #
  9. #   [1] REPOS-PATH   (the path to this repository)
  10. #   [2] TXN-NAME     (the name of the txn about to be committed)
  11. #
  12. #   [STDIN] LOCK-TOKENS ** the lock tokens are passed via STDIN.
  13. #
  14. #   If STDIN contains the line "LOCK-TOKENS:\n" (the "\n" denotes a
  15. #   single newline), the lines following it are the lock tokens for
  16. #   this commit.  The end of the list is marked by a line containing
  17. #   only a newline character.
  18. #
  19. #   Each lock token line consists of a URI-escaped path, followed
  20. #   by the separator character '|', followed by the lock token string,
  21. #   followed by a newline.
  22. #
  23. # The default working directory for the invocation is undefined, so
  24. # the program should set one explicitly if it cares.
  25. #
  26. # If the hook program exits with success, the txn is committed; but
  27. # if it exits with failure (non-zero), the txn is aborted, no commit
  28. # takes place, and STDERR is returned to the client.   The hook
  29. # program can use the 'svnlook' utility to help it examine the txn.
  30. #
  31. # On a Unix system, the normal procedure is to have 'pre-commit'
  32. # invoke other programs to do the real work, though it may do the
  33. # work itself too.
  34. #
  35. #   ***  NOTE: THE HOOK PROGRAM MUST NOT MODIFY THE TXN, EXCEPT  ***
  36. #   ***  FOR REVISION PROPERTIES (like svn:log or svn:author).   ***
  37. #
  38. #   This is why we recommend using the read-only 'svnlook' utility.
  39. #   In the future, Subversion may enforce the rule that pre-commit
  40. #   hooks should not modify the versioned data in txns, or else come
  41. #   up with a mechanism to make it safe to do so (by informing the
  42. #   committing client of the changes).  However, right now neither
  43. #   mechanism is implemented, so hook writers just have to be careful.
  44. #
  45. # Note that 'pre-commit' must be executable by the user(s) who will
  46. # invoke it (typically the user httpd runs as), and that user must
  47. # have filesystem-level permission to access the repository.
  48. #
  49. # On a Windows system, you should name the hook program
  50. # 'pre-commit.bat' or 'pre-commit.exe',
  51. # but the basic idea is the same.
  52. #
  53. # The hook program typically does not inherit the environment of
  54. # its parent process.  For example, a common problem is for the
  55. # PATH environment variable to not be set to its usual value, so
  56. # that subprograms fail to launch unless invoked via absolute path.
  57. # If you're having unexpected problems with a hook program, the
  58. # culprit may be unusual (or missing) environment variables.
  59. #
  60. # Here is an example hook script, for a Unix /bin/sh interpreter.
  61. # For more examples and pre-written hooks, see those in
  62. # the Subversion repository at
  63. # http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ and
  64. # http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/
  65. REPOS="$1"
  66. TXN="$2"
  67. # Make sure that the log message contains some text.
  68. SVNLOOK=/usr/local/bin/svnlook
  69. $SVNLOOK log -t "$TXN" "$REPOS" | \
  70.    grep "[a-zA-Z0-9]" > /dev/null || exit 1
  71. # Check that the author of this commit has the rights to perform
  72. # the commit on the files and directories being modified.
  73. commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg || exit 1
  74. # All checks passed, so allow the commit.
  75. exit 0
复制代码

作者: CrLf    时间: 2014-11-28 11:46

怎么突然变成 sh了
作者: DAIC    时间: 2014-11-28 13:19

回复 12# 潘多拉


我清楚SVN的hookscript,不管是Windows还是Linux,它被调用的时候都需要通过位置参数获取到指定的内容。
我的意思是,从10楼的截图来看,它没有获取到任何位置参数,你看%1和%2都是空的。
作者: 潘多拉    时间: 2014-11-28 14:36

回复 14# DAIC


    斯国一。。。  我去看下




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2