Added track command.
* Moves a specified file into the specified castle. * Symlinks it into its original position. Signed-off-by: Joshua Nichols <josh@technicalpickles.com>
This commit is contained in:
committed by
Joshua Nichols
parent
4776651b27
commit
58767454b3
@@ -75,6 +75,32 @@ class Homesick < Thor
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc "track FILE CASTLE", "add a file to a castle"
|
||||||
|
def track(file, castle)
|
||||||
|
castle = Pathname.new(castle)
|
||||||
|
file = Pathname.new(file)
|
||||||
|
check_castle_existance(castle, 'track')
|
||||||
|
|
||||||
|
github_user = `git config github.user`.chomp
|
||||||
|
github_user = nil if github_user == ""
|
||||||
|
github_repo = castle.basename
|
||||||
|
|
||||||
|
absolute_path = file.expand_path
|
||||||
|
castle_path = castle_dir(castle)
|
||||||
|
mv absolute_path, castle_path
|
||||||
|
|
||||||
|
inside castle_path do
|
||||||
|
system "git add #{file.basename}"
|
||||||
|
system "git commit -m \"Added #{file.basename}\""
|
||||||
|
end
|
||||||
|
|
||||||
|
inside home_dir do
|
||||||
|
absolute_path = castle_dir(castle) + file.basename
|
||||||
|
home_path = home_dir + file
|
||||||
|
ln_s absolute_path, home_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
desc "list", "List cloned castles"
|
desc "list", "List cloned castles"
|
||||||
def list
|
def list
|
||||||
#require 'ruby-debug'; breakpoint
|
#require 'ruby-debug'; breakpoint
|
||||||
@@ -94,7 +120,6 @@ class Homesick < Thor
|
|||||||
github_user = nil if github_user == ""
|
github_user = nil if github_user == ""
|
||||||
github_repo = castle.basename
|
github_repo = castle.basename
|
||||||
|
|
||||||
|
|
||||||
empty_directory castle
|
empty_directory castle
|
||||||
inside castle do
|
inside castle do
|
||||||
git_init
|
git_init
|
||||||
@@ -107,6 +132,7 @@ class Homesick < Thor
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def home_dir
|
def home_dir
|
||||||
|
|||||||
@@ -59,6 +59,22 @@ class Homesick
|
|||||||
system "git pull --quiet" unless options[:pretend]
|
system "git pull --quiet" unless options[:pretend]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def mv(source, destination, config = {})
|
||||||
|
source = Pathname.new(source)
|
||||||
|
destination = Pathname.new(destination + source.basename)
|
||||||
|
|
||||||
|
if destination.exist?
|
||||||
|
say_status :conflict, "#{destination} exists", :red unless options[:quiet]
|
||||||
|
|
||||||
|
if options[:force] || shell.file_collision(destination) { source }
|
||||||
|
system "mv #{source} #{destination}" unless options[:pretend]
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# this needs some sort of message here.
|
||||||
|
system "mv #{source} #{destination}" unless options[:pretend]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def ln_s(source, destination, config = {})
|
def ln_s(source, destination, config = {})
|
||||||
source = Pathname.new(source)
|
source = Pathname.new(source)
|
||||||
destination = Pathname.new(destination)
|
destination = Pathname.new(destination)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Homesick do
|
describe Homesick do
|
||||||
before do
|
before do
|
||||||
@@ -83,13 +83,30 @@ describe Homesick do
|
|||||||
system "git remote add origin git://github.com/technicalpickles/zomg.git >/dev/null 2>&1"
|
system "git remote add origin git://github.com/technicalpickles/zomg.git >/dev/null 2>&1"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@homesick.should_receive(:say_status).with("zomg", "git://github.com/technicalpickles/zomg.git", :cyan)
|
@homesick.should_receive(:say_status).with("zomg", "git://github.com/technicalpickles/zomg.git", :cyan)
|
||||||
@homesick.should_receive(:say_status).with("wtf/zomg", "git://github.com/technicalpickles/zomg.git", :cyan)
|
@homesick.should_receive(:say_status).with("wtf/zomg", "git://github.com/technicalpickles/zomg.git", :cyan)
|
||||||
|
|
||||||
@homesick.list
|
@homesick.list
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "track" do
|
||||||
|
it "should move the tracked file into the castle" do
|
||||||
|
some_rc_file = @user_dir.file '.some_rc_file'
|
||||||
|
homesickrepo = @user_dir.directory('.homesick').directory('repos').directory('castle_repo')
|
||||||
|
castle_path = homesickrepo.directory 'home'
|
||||||
|
|
||||||
|
# There is some hideous thing going on with construct; rming the file I'm moving works on this test.
|
||||||
|
# Otherwise when track ln_s's it back out, it sees a conflict. Its as if file operations don't
|
||||||
|
# actually effect this thing, or something.
|
||||||
|
system "rm #{some_rc_file.to_s}"
|
||||||
|
Dir.chdir homesickrepo do
|
||||||
|
system "git init >/dev/null 2>&1"
|
||||||
|
end
|
||||||
|
|
||||||
|
@homesick.should_receive(:mv).with(some_rc_file, castle_path)
|
||||||
|
@homesick.track(some_rc_file.to_s, 'castle_repo')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user