代码之家  ›  专栏  ›  技术社区  ›  David Dean

如何找到给定subversion工作副本的根文件夹

  •  23
  • David Dean  · 技术社区  · 16 年前

    我经常坐在一个颠覆性的工作拷贝的中间,我想做一个快速的工作。 svn status 了解自上次签入以来我所做的更改。然而 仅适用于当前文件夹及其子文件夹。(同样适用于 svn up (也是)

    我想要一个快速的方法来更改subversion工作副本的根文件夹,这样我就可以运行 svn状态 看看 已经更改的文件,可能是签入或更新,然后回到以前的工作岗位。

    8 回复  |  直到 16 年前
        1
  •  16
  •   David Dean    16 年前

    这是我的第一个答案:我写了一个小bash脚本,名为 svnbase :

    #!/bin/bash -u
    
    # this command outputs the top-most parent of the current folder that is still 
    # under svn revision control to standard out
    
    # if the current folder is not under svn revision control, nothing is output
    # and a non-zero exit value is given
    
    parent=""
    grandparent="."
    
    while [ -d "$grandparent/.svn" ]; do
        parent=$grandparent
        grandparent="$parent/.."
    done
    
    if [ ! -z "$parent" ]; then
        echo $parent
    else
        exit 1
    fi
    

    [~/work/scripts/XXX/code/speech-detection/framework]$ cd $(svnbase)
    [~/work/scripts/XXX]$ svn status
    ?      code/speech-detection/framework/output.old
    [~/work/scripts/XXX]$ cd -
    /home/XXXX/work/scripts/XXX/code/speech-detection/framework
    [~/work/scripts/XXX/code/speech-detection/framework]$ 
    
        2
  •  9
  •   EM0    11 年前

    在Windows上:

    svn info . |findstr /C:"Working Copy Root Path:"
    

    在Linux上:

    svn info . |grep -F "Working Copy Root Path:"
    

    FOR /F "delims=" %%i IN ('svn info . ^|findstr /C:"Working Copy Root Path:"') DO SET SOME_TEMP_VAR=%%i
    SET WORKING_COPY_ROOT=%SOME_TEMP_VAR:~24%
    
        3
  •  7
  •   Greg Hewgill    16 年前

    如果你使用 git-svn 作为Subversion客户机,您可以在本地使用Git命令透明地与Subversion存储库交互。当您使用以下命令时,Git会自动显示整个存储库中的挂起状态 git status 树上的任何地方。

        4
  •  6
  •   med_abidi    9 年前

    在具有svn的linux上,版本1.9.3(r1718519),我运行以下命令: svn info --show-item wc-root

        5
  •  2
  •   stepancheg    16 年前

    这是不可能的。SVN可以从任何深度检出,任何子目录都像全新的检出。

        6
  •  2
  •   stran    16 年前

    实际上,如果您查看.svn/entries文件,您会发现其中列出的基通常在第6行附近。无论如何,svn url的格式将为您提供一些重要线索:P 哦,是的,我冒昧地看了看 svn info 我也会告诉你。

    ……唉,你不是这么问的。我喜欢第一个答案中的答案:P

        7
  •  1
  •   0x777    8 年前

    在工作副本的任何深度尝试以下命令:

    svn info . --show-item wc-root --no-newline
    
        8
  •  0
  •   John Zabroski    7 年前

    这是我的解决方案,它是各种解决方案的混合体。它是在PowerShell中编写的,因为我正在编写的PowerShell模块需要它。

    <#
        This command outputs the top-most parent of the current folder.
    
        If the current folder is not under svn revision control,
        it will recurse up one level, and try again.
    
        It stops at the root folder on the current drive.
        If the current folder's drive's root folder is not under svn revision control,
        it will throw an exception "No SVN Root Directory found."
    #>
    function Get-SvnRootDirectory {
        $currentDirectory = Get-Location
    
        do {
            $output = $(svn info $currentDirectory 2> $null)
            $output = $output | findstr /C:"Working Copy Root Path:"
            if ($LASTEXITCODE -eq 0)
            {
                break;
            }
            # if (Test-Path -PathType Container -Path $currentDirectory)
            # {
            #     throw "No SVN Root Directory found."
            # }
            $currentDirectory = Split-Path -Path $currentDirectory -Parent
            if ([string]::IsNullOrWhiteSpace($currentDirectory))
            {
                throw "No SVN Root Directory found."
            }
        }
        while ($true)
    
        $output -match "Working Copy Root Path: (?<Group>.*)$" | Out-Null
        return $Matches.Group
    }