标题: [文件操作] 批处理怎样实现前缀不带有指定字符串不能提交? [打印本页]
作者: 潘多拉 时间: 2014-11-27 11:25 标题: 批处理怎样实现前缀不带有指定字符串不能提交?
- setlocal
- set svnlook="F:\Program Files (x86)\VisualSVN Server\bin\svnlook.exe"
- set REPOS=%1
- set TXN=%2
-
- rem 过滤文件类型
- %svnlook% changed -t %TXN% %REPOS%|findstr /I "txt$"
- if %errorlevel% EQU 0 (goto err1)
-
- :ok
- exit 0
-
- :err1
- echo. >&2
- echo 错误:禁止提交前缀名错误的文件 ... >&2
- 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给出的一个钩子文件的模板(用于在提交之前做限制)我附上一个解释文档。- #!/bin/sh
-
- # PRE-COMMIT HOOK
- #
- # The pre-commit hook is invoked before a Subversion txn is
- # committed. Subversion runs this hook by invoking a program
- # (script, executable, binary, etc.) named 'pre-commit' (for which
- # this file is a template), with the following ordered arguments:
- #
- # [1] REPOS-PATH (the path to this repository)
- # [2] TXN-NAME (the name of the txn about to be committed)
- #
- # [STDIN] LOCK-TOKENS ** the lock tokens are passed via STDIN.
- #
- # If STDIN contains the line "LOCK-TOKENS:\n" (the "\n" denotes a
- # single newline), the lines following it are the lock tokens for
- # this commit. The end of the list is marked by a line containing
- # only a newline character.
- #
- # Each lock token line consists of a URI-escaped path, followed
- # by the separator character '|', followed by the lock token string,
- # followed by a newline.
- #
- # The default working directory for the invocation is undefined, so
- # the program should set one explicitly if it cares.
- #
- # If the hook program exits with success, the txn is committed; but
- # if it exits with failure (non-zero), the txn is aborted, no commit
- # takes place, and STDERR is returned to the client. The hook
- # program can use the 'svnlook' utility to help it examine the txn.
- #
- # On a Unix system, the normal procedure is to have 'pre-commit'
- # invoke other programs to do the real work, though it may do the
- # work itself too.
- #
- # *** NOTE: THE HOOK PROGRAM MUST NOT MODIFY THE TXN, EXCEPT ***
- # *** FOR REVISION PROPERTIES (like svn:log or svn:author). ***
- #
- # This is why we recommend using the read-only 'svnlook' utility.
- # In the future, Subversion may enforce the rule that pre-commit
- # hooks should not modify the versioned data in txns, or else come
- # up with a mechanism to make it safe to do so (by informing the
- # committing client of the changes). However, right now neither
- # mechanism is implemented, so hook writers just have to be careful.
- #
- # Note that 'pre-commit' must be executable by the user(s) who will
- # invoke it (typically the user httpd runs as), and that user must
- # have filesystem-level permission to access the repository.
- #
- # On a Windows system, you should name the hook program
- # 'pre-commit.bat' or 'pre-commit.exe',
- # but the basic idea is the same.
- #
- # The hook program typically does not inherit the environment of
- # its parent process. For example, a common problem is for the
- # PATH environment variable to not be set to its usual value, so
- # that subprograms fail to launch unless invoked via absolute path.
- # If you're having unexpected problems with a hook program, the
- # culprit may be unusual (or missing) environment variables.
- #
- # Here is an example hook script, for a Unix /bin/sh interpreter.
- # For more examples and pre-written hooks, see those in
- # the Subversion repository at
- # http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ and
- # http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/
-
-
- REPOS="$1"
- TXN="$2"
-
- # Make sure that the log message contains some text.
- SVNLOOK=/usr/local/bin/svnlook
- $SVNLOOK log -t "$TXN" "$REPOS" | \
- grep "[a-zA-Z0-9]" > /dev/null || exit 1
-
- # Check that the author of this commit has the rights to perform
- # the commit on the files and directories being modified.
- commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg || exit 1
-
- # All checks passed, so allow the commit.
- 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://www.bathome.net/) |
Powered by Discuz! 7.2 |