Skip to content

fniessen/svn-leuven

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Awesome SVN commands and extra config

How to fix “unable to create pristine install stream”

cd .svn
rm -rf tmp
mkdir tmp

colordiff

Use colordiff for my svn diff command (set in ~/.subversion/config):

diff-cmd = colordiff

SHOW - View your changes

To compare all modified files in your working copy with the HEAD revision in the repository, use the following command:

alias svn-diff-all="svn status \
    | grep '^M' \
    | awk '{print $2}' \
    | xargs svn diff -r HEAD"

Colored svn diff command like git diff.

alias svn-diff='svn diff --diff-cmd=colordiff --extensions=" -u --strip-trailing-cr --ignore-space-change " \
    | less --quit-if-one-screen'

SHOW - View the commit history

The following aliases are interesting for using SVN a bit like Git.

One-line log format (‘git log’)

# Original author: Plexus.

# Convert the "svn log" output into a one liner format, which is easier to grep
# or use in scripts. Pipe "svn log" into this script

# When we get a line that starts with a revision number, put the data in variables
/^r[0-9]+/ {
    rev=$1
    user=$3
    date=$5
    time=$6
}

# Anything that isn't a revision line, a separator line or an empty line
# will be part of the commit message. Concatenate these into the comment variable
! (/^r[0-9+]/ || /^-+$/ || /^$/) {
  comment = comment $0 " "
}

# With every separator line, output what we stored before and reset the comment variable
# To skip the first line we also check if we've already stored a revision
/^-+$/ && rev {
   print date " | " rev " | " user " | " comment
   comment = ""
}
# Usage: svn-log
svn log \
    | svn-log-shorten \
    | sed -e 's/^\(.*\) | \(.*\) | \(.*\) | \(.*\)$/\o33\[0;32m\1\o33[0m \o33\[0;33m\2\o33[0m \4\o33\[1;34m<\3>/' \
    | less -RF

Make status checks of your working copy easier

Add them to your .bashrc:

alias svnl="svn log -r 1:HEAD -v"       # Show log messages.
alias svnm="svn status -u -q"           # Show locally/repository changed items.
alias svnn="svn status -q"              # Show locally changed items.
alias svns="svn status -u -q -v"        # Show status of all items.

Show a single revision (‘git show’)

svn diff -c 4795                        # Or svn diff -r 4795:4792.

See svn-show and svn-showtool in my Shell configuration.

List all the changed files in a commit

Output filenames of files changed in a commit.

# Usage: svn-changed-files @REV
svn log -v -r $1

Show the history of a file

To view all historical changes to a file in SVN:

svn log -q path/to/file | grep "^r" | awk '{print $1}' # List of revisions.

See svn-filelog in my Shell configuration.

Show the history of a file (with diff)

svn log --diff path/to/file

See svn-filelog-p in my Shell configuration.

Search

# Usage: svn-search-commits ARG
svn log --search "$1" \
    | svn-log-shorten \
    | sed -e 's/^\(.*\) | \(.*\) | \(.*\) | \(.*\)$/\o33\[0;33m\1\o33[0m \o33\[0;32m\2\o33[0m \4\o33\[1;34m<\3>/'

Searching subversion history (full text)

Search the actual diffs of the commit history, and not filenames and/or commit messages. https://stackoverflow.com/questions/44176/searching-subversion-history-full-text

Add / Delete

Add all new files:

svn st | grep ^? | awk {'print $2'} | xargs svn add

Delete all locally missing files:

svn st | grep ^! | awk {'print $2'} | xargs svn rm
svn st | grep ^! | cut -d! -f2| sed 's/^ *//' | sed 's/^/"/g' | sed 's/$/"/g' | xargs svn rm

Commit:

svn commit -m "Commit message"

REVERT - Undo things

svn merge -r 1944:1943 . should revert the changes of r1944 in your working copy. You can then review the changes in your working copy (with diff), but you’d need to commit in order to apply the revert into the repository.

“Unmodify” files

To discard local changes in current folder (revert a whole directory of files) :

svn revert -R .

“Unadd” a file to SVN before commit

svn rm --keep-local folder_name

because

svn revert --recursive folder_name

is unsafe, as it looses all local changes.

Conflicts

Files marked as conflicted show up with a C in svn status, and SVN will refuse to commit such files.

Use svn resolved filename to mark a conflicted file as resolved:

svn status -q

svn resolve --accept=theirs-full
svn resolved (FILE)

svn status -q

UPDATE - Pull

http://stackoverflow.com/questions/182945/how-to-see-what-will-be-updated-from-repository-before-issuing-svn-update-comm

Depending on what you want to know between your working copy and the latest SVN server repository, without updating your local working copy, here is what you can do:

If you want to know what has been changed in SVN server repository, run command:

svn st -u

If you want to know if the same file has been modified both in your local working copy and in SVN server repository, run command:

svn st -u | grep -i "^M \{7\}\*"

If you want to get list of files changed between a particular revision and HEAD, run the command:

svn diff -r revisionNumber:HEAD --summarize

If you want to get a list of files changed between particular revisions, run the command:

svn diff -r revisionNumber:anotherRevisionNumber --summarize

If you want to know what content of a particular file has been changed in SVN server repository compared with your working copy, run the command:

svn diff -r BASE:HEAD path/to/file

If you want to know what contents of all the files have been changed in SVN server repository compared with your working copy, run the command:

svn diff -r BASE:HEAD .

If you want to get a list of all files that were changed on the branch (created, say, at revision 22334) compared to what’s on the trunk (without seeing files that were changed on the trunk between when the branch was created and “now”):

svn diff -r 22334:HEAD --summarize <url of the branch>

Check for incoming changes

Show which files are modified in the repository (with an *):

# Usage: svn-incoming
svn status -u | grep \*
svn log -r BASE:HEAD                    # Equivalent of `git log'.
svn log --diff -r BASE:HEAD             # Equivalent of `git log -p'.

Preview incoming changes

See what has been changed (how it’s different from my working copy):

svn diff -r BASE:HEAD

Checkout a specific older version of the source code

Assuming that the source has already been checked out (that is you have an already existing folder…), update the revision (say we want to get r4732):

svn update -r 4732

Ignore files

Edit the file ignoring.txt to put the files you want actually to ignore. Then use this one to ignore the files listed in the file:

svn propset svn:ignore -F ignoring.txt .

Note the dot at the end of the line. It tells SVN that the property is being set on the current directory.

Delete the file:

rm ignoring.txt

Finally commit,

svn ci --message "Ignore some files"

You can then check which files are ignored via:

svn proplist -v

Ignore files from the command line

Add a file (or a file glob pattern) to ignore without deleting the previous value of the svn:ignore property… from the command line.

# Usage: svn-ignore admin/notes/\*.tex

target="$1"
targetdirectory=$(dirname $target)
targetfilepattern=$(basename $target)

svnignores=$(svn propget svn:ignore "$targetdirectory")
svnignores="$svnignores"$'\n'"$targetfilepattern"
printf "Ignore '$targetfilepattern'\n"
svn propset svn:ignore "$svnignores" "$targetdirectory"

PUBLISH - Prepare a release

SVN diff zip revision to deploy.

Make release package (get list of changed files via svn diff log and zip them):

svn-rev-patch:

# For one release only.
svn diff -c 124 --summarize | cut -c 9- | xargs zip -9 commit-124.zip

# For a range of releases (124 up to and INCLUDING 145).
svn diff -r 123:145 --summarize | cut -c 9- | xargs zip -9 commit-124-145.zip

This will create a ZIP file with the changed file(s) – in an intact directory structure – from revision 123:HEAD.

Commands

:header-args+: :tangle .shell/.aliases-svn
# Search through files, ignoring .svn directories.
alias svn-find='find . -not \( -name .svn -prune \)'

# Grep a string in every SVN revision of a file.
# Usage: svn-grep-all-rev PATTERN FILE
svn-grep-all-rev() {
    svn log "$2" \
        | perl -n -e 'print "$1\n" if m/^r(\d*)\s+/' \
        | (
              while read revision; do
                  printf "\e[0;33m%s\e[0m\n" "Revision $revision:"
                  svn cat -r "$revision" "$2" | grep "$1"
                  printf '\n'
              done
          )
}
# Get the URL of the remote SVN repository.
alias svn-remote-get-url="svn info | grep -E '^URL: ' | sed 's/^URL: //'"

This alias can be used as:

svn COMMAND $(svn-remote-get-url)       # Retrieve the full RepoURL.
#? svn-status, Time-stamp: <<current-time()>>
#? Copyright (C) 2020-2022 Fabrice Niessen
#?
#? License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
#? This is free software: you are free to change and redistribute it.
#? There is NO WARRANTY, to the extent permitted by law.

##? Usage: svn-status [options]
##?
##? Print the colored status of working copy files and directories.
##?
##? Options:
##?   -h, --help                    display this help and exit
##?   -V, --version                 display version information and exit

set -euo pipefail

# Check if docopts command is available.
if ! command -v docopts > /dev/null 2>&1; then
    printf >&2 'Error: docopts command not found.\n'
    exit 2
fi

# Extract help and version information from the script.
help=$(grep "^##?" "$0" | cut -c 5-)
version=$(grep "^#?" "$0" | cut -c 4-)

# Get command-line arguments.
args="$(docopts -h "$help" -V "$version" : "$@")"
eval "$args"

svn status \
    | sed -e 's/^\(\([A-Z]\s\+\(+\s\+\)\?\)\?C .*\)$/\o33\[1;35m\1\o33[0m/' \
          -e 's/^\(\s*M.*\)$/\o33\[1;33m\1\o33[0m/' \
          -e 's/^\(A.*\)$/\o33\[1;32m\1\o33[0m/' \
          -e 's/^\(?.*\)$/\o33\[0;36m\1\o33[0m/' \
          -e 's/^\(\(D\|~\).*\)$/\o33\[1;31m\1\o33[0m/' \
    | less -RF
alias svn-st=svn-status
# Usage: svn-show @REV
svn diff -c "$1" | less
# svn-showtool @REV PATH
svn-showtool() {
    svn diff --diff-cmd='meld' -c "$1" "$2"
}
# Usage: svn-file-history-diff PATH
svn-file-history-diff() {
    svn log --diff "$1" | less
}
# Usage: svn-unmodify PATH
svn-unmodify() {
    svn revert "$1"
}
alias svn-nevermind='read -p "Destroy all local changes? [y/N]" \
    && [[ $REPLY =~ ^[yY] ]] \
    && svn revert . -R \
    && rm -rf $(awk -f <(echo "/^?/{print \$2}") <(svn status) ;)'

Nuclear version which:

  • reverts tracked files (discards changes in the working directory), and
  • cleans untracked files and directories (removes any new files).

See https://stackoverflow.com/questions/6204572/is-there-a-subversion-command-to-reset-the-working-copy.

About

SVN aliases and extra commands

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published