无论如何要为特定的 repo 重置 svn 缓存的身份验证?

Anyway to reset svn cached auths for a specific repo?

我一直在寻找这个,我很惊讶我还没有找到它。

我正在使用 Windows 7. 我有 TortoiseSVN 1.8 和可用的命令行工具,但如果有使用另一个客户端的解决方案,我愿意接受其他选项。

我正在尝试为 svn 客户端上的特定存储库重置缓存的授权。

我有一组项目(~15 个)是一起构建的。我们使用 svn 命令行客户端设置了批处理文件,以检查和构建在各个开发人员机器上运行良好的项目,因为 svn 客户端缓存了他们的凭据。

但是,我们正在为发布设置一个中央构建机器(而不是让一个人负责发布构建),我们希望任何人都能够登录并 运行 使用他们自己的构建凭据。

我们遇到的问题是,如果我们让 svn 客户端使用它的默认设置,那么任何登录到该机器的人都将使用前一个人的凭据。如果我们将 svn 客户端切换为不缓存凭据,那么构建过程(所有脚本都记得)必须提示每个项目,这会导致用户输入密码约 15 次才能进行构建。

我们是一家大公司的一部分,我们的 svn 服务器为其他团队提供了许多不同的存储库,一些开发人员使用多个存储库,所以我不能简单地在构建后清除缓存目录,因为那样会清除所有缓存的存储库而不仅仅是我们的(据我所知,svn 只通过服务器缓存,而不是通过 repo)。

是否有任何我可以实施的解决方案将在批处理文件中从 svn 中提取的第一个项目提示输入 svn 凭据,将这些凭据用于脚本中的所有项目,然后仅清除那些缓存的凭据脚本完成后的项目(或整个回购协议)?

我尝试了几种不同的方法来尝试 "reset" 特定项目的凭据,但我没有任何运气。即使我的脚本必须单独重置它们,也没关系。

有人在另一个 so thread 上建议在项目上使用 svn switch 并在完成后通过 --username 提供不同的用户,但这似乎在 windows 上不起作用(他们使用 OSX).下次我 运行 脚本时,它只是默认为最后一个经过身份验证的用户。

-edit- 添加了脚本的简化版本:

@ECHO OFF
pushd %~dp0

SET SVN=https://domain.com:81/svn/repo
SET TAG=%1

CALL :GET_PROJECT_TAG project1
CALL :GET_PROJECT_TAG project2
CALL :GET_PROJECT_TAG project3
CALL :GET_PROJECT_TAG project4
CALL :GET_PROJECT_TAG project5
CALL :GET_PROJECT_TAG project6
GOTO :END

:GET_PROJECT_TAG
svn export %SVN%/%1/tags/%TAG%/ %TAG%/%1/
EXIT /B

:END
popd
PAUSE

-结束编辑-

想法?

如果未定义,让批处理脚本提示输入凭据怎么办?使用 @echo off 正下方的 setlocal 使脚本在退出时忘记凭据。如果您想屏蔽密码输入,可以使用 PowerShell 命令来完成。

<NUL set /P "=Password? "
set "psCommand=powershell -command "$p=read-host -AsSecureString;^
$m=[System.Runtime.InteropServices.Marshal];$m::PtrToStringAuto($m::SecureStringToBSTR($p))""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set "pass=%%p"

echo You entered %pass%

然后只要脚本是 运行,就可以根据需要在所有 svn 命令中重复使用 %pass%。如果通过 GUI 提示您输入身份验证信息,那么使用 Subversion for Windows 代替 TortoiseSVN 是否可以解决您的问题?

编辑: 我觉得我应该注意,期望密码中的特殊字符可能会破坏您的脚本并不是不合理的。每当您检索 %pass% 变量时,您应该以延迟扩展样式执行此操作,以防止计算 ^< 等字符。 但是在检索之前不要启用延迟扩展。 如果在输入过程中启用延迟扩展,感叹号可能会被去除。这样做:

@echo off
setlocal

<NUL set /P "=Password? "
set "psCommand=powershell -command "$p=read-host -AsSecureString;^
$m=[System.Runtime.InteropServices.Marshal];$m::PtrToStringAuto($m::SecureStringToBSTR($p))""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set "pass=%%p"

setlocal enabledelayedexpansion
echo You entered !pass!
endlocal

这是我用来临时清除缓存凭据的几个批处理文件。您可以轻松修改它们以满足您的特定需求。

:: ClearCachedCredentials.bat
:: 2015-10-30 Kurt Schultz - Tested on Windows 7, 64-bit
:: Move the current TortoiseSVN credential cache files to a backup folder.
:: This allows you to log on to Subversion using a different set of credentials.
:: The original credentials can be restored by running RestoreCachedCredentials.bat
::
:: Alternatively, you can open the individual files in the svn.simple folder using
:: a text editor and look for the user ID that you want to remove from the cache.
:: Remove or delete the file as needed.

@set filePath=\Users\%username%\Application Data\Subversion\auth
@set fileCount=0
@If not exist "C:%filePath%" (
    @echo Cannot locate "C:%filePath%"
    @echo Do you have Tortoise SVN installed?
) Else (
    @C:
    @CD "%filePath%"
    @for /f %%A in ('dir /b /a-d "svn.simple\*" 2^>nul ^| find /v /c "" ') do @set /a fileCount+=%%A
    @Rem When the dir command is issued from the command line, there must be a space between the carat and the pipe e.g. ^ |
    @Rem or you will get an error, invalid switch - "v".  When inside the "for" command, the space cannot be there.
)

:: I had to move the following section out of the section above in order to test the value of fileCount.
:: When it was inside the Else block above, the value was always 0.
@If %fileCount%==0 (
    @echo There were no cached files to backup or clear.
) Else (
    @dir svn.simple
    @echo.
    @echo These credentials will be moved to the backup folder.
    @echo.
    @echo Press Ctrl-C now to abort or
    @pause
)

:: I had to move the following section out of the section above and into its own If condition
:: in order to get the Ctrl-C to work correctly.  (The file move did not occur, but the echo
:: statements were still executed.
@If Not %fileCount%==0 (
    @If not exist backup (
       @md backup
       )

    @If not exist backup\svn.simple (
       @md backup\svn.simple
       )

    @move svn.simple\*.* backup\svn.simple
    @echo.
    @echo The TortoiseSVN credentials have been backed up and cleared.
    @echo Run RestoreCachedCredentials.bat to restore them.
)
@echo.
@pause


:: RestoreCachedCredentials.bat
:: 2015-10-30 Kurt Schultz - Tested on Windows 7, 64-bit
:: Restore the TortoiseSVN credential cache files from the backup folder.

@set continue=false
@set filePath=\Users\%username%\Application Data\Subversion\auth
@If not exist "C:%filePath%" (
    @echo Cannot locate "C:%filePath%"
    @echo Do you have Tortoise SVN installed?
) Else (
    @C:
    @CD "%filePath%"
    @If not exist backup\svn.simple (
    @Echo The backup directory does not exist.  There is nothing to restore.
    @Echo You must first use ClearCachedCredentials.bat to create a backup.
    ) Else (
    @echo This will restore the Subversion credentials from your backup folder.
    @echo Press Ctrl-C now to abort or
    @pause
    @set continue=true
    )
)
@If %continue%==true (
    @copy backup\svn.simple\*.* svn.simple
    @echo.
    @echo The TortoiseSVN credentials have been restored.
)
@echo.
@pause