How can I find the root folder of a given subversion working copy

后端 未结 8 738
暗喜
暗喜 2020-12-09 15:44

Quite often I\'m sitting in the middle of a subversion working copy, and I want to do a quick svn status to find out what changes I have made since the last che

相关标签:
8条回答
  • 2020-12-09 16:18

    On linux with svn, version 1.9.3 (r1718519), I run this: svn info --show-item wc-root

    0 讨论(0)
  • 2020-12-09 16:19

    actually, if you look in your .svn/entries file, you'll find the base listed in there usually around line 6. In any event, the format of your svn url will give you some significant clues :P Oh yeah, i took the liberty of looking, and svn info will also tell you.

    ...sigh, that's not what you asked though. I like the solution in the first answer :P

    0 讨论(0)
  • 2020-12-09 16:20

    On Windows:

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

    On Linux:

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

    It can be assigned to a variable using a little string manipulation. Windows version:

    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%
    
    0 讨论(0)
  • 2020-12-09 16:23

    It is not possible. SVN can be checked out from any depth, and any subdir acts like brand new checkout.

    edit: svnbase script in prev comment works, but it is not precise.

    0 讨论(0)
  • 2020-12-09 16:29

    Try the following command at any depth of your working copy:

    svn info . --show-item wc-root --no-newline
    
    0 讨论(0)
  • 2020-12-09 16:30

    Here's my first go at an answer: I wrote a little bash script called 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
    

    So now I can do this:

    [~/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]$ 
    
    0 讨论(0)
提交回复
热议问题