Created
April 25, 2010 22:59
-
-
Save jelder/378799 to your computer and use it in GitHub Desktop.
Take advantage of environments where /home is an NFS export from the server which also hosts Subversion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Take advantage of environments where Subversion server also NFS exports /home to make more efficient Subversion operations. | |
require 'net/ssh' | |
server = "admin01" | |
temporary_root = "file:///srv/svn" | |
pwd = ENV["PWD"] | |
user = ENV["USER"] | |
remote_command = "cd #{pwd} && svn " + ARGV.join(" ") | |
lock_file = ".qsvn_lock" | |
if File.exists?(lock_file) | |
puts "#{pwd} is locked by another qsvn process" | |
exit 1 | |
else | |
File.new(lock_file, File::CREAT) | |
end | |
Net::SSH.start( server, user ) do |ssh| | |
remote_root = ssh.exec!("svn info #{pwd}")[/Root: (.*)/, 1] | |
repository_name = remote_root.split("/")[-1] | |
temporary_root += "/" + repository_name | |
puts "Temporarily using #{temporary_root} for repository root." | |
ssh.exec!("svn switch --relocate #{remote_root} #{temporary_root}/#{repository_name} #{pwd}") | |
puts "Running: #{remote_command}" | |
puts ssh.exec!(remote_command) do |channel, stream, data| | |
print data | |
end | |
puts "Restoring original repository root, #{remote_root}." | |
ssh.exec!("svn switch --relocate #{temporary_root}/#{repository_name} #{remote_root} #{pwd}") | |
end | |
File.delete(lock_file) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment