Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-10 of 35 total  RSS 

SVN Diff While Ignoring Whitespace

A command line alias for doing an svn diff while ignoring whitespace differences. Placed in ~/.bashrc or your profile.

Can be used in a directory:
$ dw

Or on a single file:
$ dw functions.php

alias dw="svn diff --diff-cmd diff -x -uw"

Resolve all SVN conflicts with the right version of the file

This small PHP shell script recourses through the subdirectories and looks for files that match the "conflict" files that SVN creates when merging from another branch. It chooses the "right" version of the files and resolves the conflict.


$dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("."));
foreach($dir as $file)
{
  $path = $file->getPathname();
  if (preg_match('/\.merge-right\.r\d+$/', $path, $matches)) {
    $orig = str_replace($matches[0], '' , $path);
    copy($path, $orig);
    $cmd = "svn resolved $orig";
    `$cmd`;
  }
}

Rename old HTML views for Rails 2

# Snagged from http://softiesonrails.com/2007/7/11/upgrading-your-views-to-rails-2-0
for old in `find app/views -name *.rhtml`; do svn mv $old `dirname $old`/`basename $old .rhtml`.html.erb; done

Checkout a Git clone of an SVN repository in parent folder

Here is a quick executable cmd that you run inside a folder checked out with Subversion. It will clone the repository using Git into the parent folder as <projname>.git

Stick this code into ~/bin/gitify and add ~/bin to your path:

#!/usr/bin/env ruby -wKU

# get svn info location
svnurl = `svn info | grep "^URL:"`.gsub('URL: ','').chomp

# project = basename
project = File.basename(Dir.pwd)

puts cmd = "git-svn clone #{svnurl} ../#{project}.git"

`#{cmd}`

svn merging

svn log | more
svn merge -r339:HEAD https://wush.net/svn/givezooks/trunk

svn-add-all-new-files

alias svn-add-all-new-files='svn st|grep ^?|sed s/?//|xargs svn add $1'

Subversion basic commands Part I

New users to SVN should be familiar with the following commands. Examples based on the code from Gentoo-wiki - HOWTO subversion SVN http://urltea.com/1urj .

#server side

# create the project directory structure outside of svn
mkdir -p ~/Documents/code/my-project/{trunk,tags,branches} 

# create the new repository
svnadmin create /var/svn/my-repository 

# add the new project
svn import my-project file:////var/svn/my-repository/my-project

# remove the project
rm -rf /var/svn/my-repository/my-project 


#client side

# list the contents of my-project
svn list --verbose http://my-site.com/svn/my-repository/my-project 


# *update 29-Oct-07*
# it's possible to import, or remove the project from the client-side

# add the new project
svn import my-project http://my-site.com/svn/my-repository/my-project 

# remove the project
svn delete http://my-site.com/svn/my-repository/my-project 



Note: To use http on the client side, it's necessary to have Apache configured using SVN and DAV. Refer to HOWTO Apache2 with subversion SVN and DAV. http://urltea.com/1uqg

Ignore a folder in subversion

# In this case, ignore contents of 'coverage' folder in current directory.
svn propset svn:ignore 'coverage' .

Remove all .svn folders from directory recursively

find . -name .svn -print0 | xargs -0 rm -rf

Adding new files to a Subversion Repo

# List all new files
svn st | grep ? | sed "s/^? //"

# Add all new files
svn st | grep ? | sed "s/^? //" | xargs svn add

# Another way to add all new files
svn add * --force
« Newer Snippets
Older Snippets »
Showing 1-10 of 35 total  RSS