Check that an svn repository url does not exist

后端 未结 6 1145
别那么骄傲
别那么骄傲 2021-02-01 12:47

I am writing a script which will add a new project in the repository, based on the name supplied by the user. Part of this involves checking that an url with the same name does

相关标签:
6条回答
  • 2021-02-01 13:27

    You can just use

    svn ls https://developernetwork.repo.net/svn/Projects/Calculator/
    

    It will tell you if the repository(directory) exist or not.

    Update

    for directories with many files use:

    svn ls http://server/svn/foo --depth empty
    
    0 讨论(0)
  • 2021-02-01 13:27

    I face the above problem and i tried all the way. not work for me.. if we access svn with a path not in svn it's failed with error and the shell script will break.

    Instead of accessing unknown path, what i did is get the directory list of parent folder and check whether matching one contain or not.

    Get all the projects form your Parent directory (if you want to find a specific tags then your parent directory path should be https://developernetwork.repo.net/svn/Projects/Calculator/tags)

    projects=$(svn ls https://developernetwork.repo.net/svn/Projects/)
    

    then check your project folder exists. Remember to add / after your project name.

    projectName="Calculator/"
    for i in $projects; do 
        if [ "$i" == "$projectName/" ];
            then
            echo Project Exist
            else
            echo Project does not exist
        fi
    done 
    

    simple.

    0 讨论(0)
  • 2021-02-01 13:31

    I'd have commented on an existing answer but I don't have sufficient reputation.

    I wanted to find if a file had been imported successfully or not so I tried "svn info" and "svn ls" with "echo $?". I could only get a zero/non-zero return code when I used "svn ls": "svn info" always returned zero.

    This was with subversion 1.5.5 on Redhat RHEL6.

    0 讨论(0)
  • 2021-02-01 13:37

    Instead of checking for return strings I would just check for the return code:

    both

    svn ls REPOSITORY/PATH
    

    and

    svn info REPOSITORY/PATH
    

    return 0 if all went fine, and 1 if things went wrong; you can quickly check it out:

    echo $?
    

    so in a bash script just do something like:

    error=$?
    if [ $error -ne 0 ]; then
          YOUR ERROR HANDLING
    fi
    

    works like a treat!

    0 讨论(0)
  • 2021-02-01 13:50

    To receive information about any existing repository (e.g. for possibly enriching an error message) you could also use

    svn info https://developernetwork.repo.net/svn/Projects/Calculator/
    

    For a non-existing project it will just return

    svn: Could not open the requested SVN filesystem
    
    0 讨论(0)
  • 2021-02-01 13:53

    Like @A Scott says, the echo $? can't be used to know wether the URL is correct (I'm on Mac OS 10.11 and SVN client 1.9.5).

    For potential future readers, i use this workaround :

    content=$(svn info $SVN_TAG_URL)
    
    if [[ -z $content ]]; then
        echo "The SVN URL doesn't exist"; exit
    fi
    
    0 讨论(0)
提交回复
热议问题