Compare commits
77 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a2df591c0 | ||
|
|
4923265dea | ||
|
|
79421580e9 | ||
|
|
cabde9e5f1 | ||
|
|
0d60ae9d1a | ||
|
|
d5317b8e17 | ||
|
|
3b8a5b4be4 | ||
|
|
6590a1eeff | ||
|
|
693ae5f05e | ||
|
|
da3002f199 | ||
|
|
feaaab2fa4 | ||
|
|
59f75711a4 | ||
|
|
f24030b51f | ||
|
|
71bb120a12 | ||
|
|
85f46e01b1 | ||
|
|
c5b24b9b38 | ||
|
|
68460af45e | ||
|
|
5614b6b8b3 | ||
|
|
570b063632 | ||
|
|
1d398587d0 | ||
|
|
085853faaa | ||
|
|
21b4e344a9 | ||
|
|
a6194dfe8b | ||
|
|
5692194fa2 | ||
|
|
11745098c2 | ||
|
|
b1bb0c996c | ||
|
|
a62039da50 | ||
|
|
4bfd1c60c2 | ||
|
|
f0e11abb5b | ||
|
|
ed397bdaf8 | ||
|
|
2f5e20d963 | ||
|
|
cc83a4e1fa | ||
|
|
dcc5cb0bc1 | ||
|
|
978416d1e4 | ||
|
|
1c12c73e4b | ||
|
|
1016002638 | ||
|
|
6431a864ad | ||
|
|
42f661cfbf | ||
|
|
7632591681 | ||
|
|
a9a5b81dc5 | ||
|
|
721c10cffd | ||
|
|
332aad8ad0 | ||
|
|
171b4c1fb8 | ||
|
|
60d4458bbc | ||
|
|
9ad171ab78 | ||
|
|
5918746059 | ||
|
|
4641843ffd | ||
|
|
1a181b907c | ||
|
|
fb7595d254 | ||
|
|
c8f0999035 | ||
|
|
46faec7857 | ||
|
|
e35d3fe6ba | ||
|
|
ba620e0f7f | ||
|
|
5700f55dc3 | ||
|
|
2c92010093 | ||
|
|
03490531d8 | ||
|
|
7bd9759e81 | ||
|
|
a808f56caf | ||
|
|
b7e2b45e69 | ||
|
|
63c45d7c3a | ||
|
|
096067ac62 | ||
|
|
8d6bf4c0c5 | ||
|
|
882b862780 | ||
|
|
e06a5d6300 | ||
|
|
7451e8c739 | ||
|
|
f034f773c5 | ||
|
|
681fd98dc3 | ||
|
|
e57b139e32 | ||
|
|
b64bfe2bb6 | ||
|
|
ee04b5788a | ||
|
|
2e8d431ab5 | ||
|
|
3465c37c0e | ||
|
|
bf6894e313 | ||
|
|
77e3f7f479 | ||
|
|
753f5027b0 | ||
|
|
23c012a527 | ||
|
|
895543641b |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -46,3 +46,8 @@ pkg
|
||||
|
||||
Gemfile.lock
|
||||
vendor/
|
||||
|
||||
homesick*.gem
|
||||
|
||||
# rbenv configuration
|
||||
.ruby-version
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
language: ruby
|
||||
rvm:
|
||||
- 2.1.0
|
||||
- 2.0.0
|
||||
- 1.9.3
|
||||
- 2.4.0
|
||||
- 2.3.3
|
||||
- 2.2.6
|
||||
sudo: false
|
||||
|
||||
@@ -1,3 +1,28 @@
|
||||
#1.1.5
|
||||
* Fixed problem with version number being incorrect.
|
||||
|
||||
#1.1.4
|
||||
* Make sure symlink conflicts are explicitly communicated to a user and symlinks are not silently overwritten
|
||||
* Use real paths of symlinks when linking a castle into home
|
||||
* Fix a problem when in a diff when asking a user to resolve a conflict
|
||||
* Some code refactoring and fixes
|
||||
|
||||
#1.1.3
|
||||
* Allow a destination to be passed when cloning a castle
|
||||
* Make sure `homesick edit` opens default editor in the root of the given castle
|
||||
* Fixed bug when diffing edited files
|
||||
* Fixed crashing bug when attempting to diff directories
|
||||
* Ensure that messages are escaped correctly on `git commit all`
|
||||
|
||||
#1.1.2
|
||||
* Added '--force' option to the rc command to bypass confirmation checks when running a .homesickrc file
|
||||
* Added a check to make sure that a minimum of Git 1.8.0 is installed. This stops Homesick failing silently if Git is not installed.
|
||||
* Code refactoring and fixes.
|
||||
|
||||
#1.1.0
|
||||
* Added exec and exec_all commands to run commands inside one or all clones castles.
|
||||
* Code refactoring.
|
||||
|
||||
#1.0.0
|
||||
* Removed support for Ruby 1.8.7
|
||||
* Added a version command
|
||||
|
||||
38
Gemfile
38
Gemfile
@@ -1,26 +1,36 @@
|
||||
require 'rbconfig'
|
||||
source 'https://rubygems.org'
|
||||
|
||||
this_ruby = Gem::Version.new(RUBY_VERSION)
|
||||
ruby_230 = Gem::Version.new('2.3.0')
|
||||
|
||||
# Add dependencies required to use your gem here.
|
||||
gem "thor", ">= 0.14.0"
|
||||
gem 'thor', '>= 0.14.0'
|
||||
|
||||
# Add dependencies to develop your gem here.
|
||||
# Include everything needed to run rake, tests, features, etc.
|
||||
group :development do
|
||||
gem "rake", ">= 0.8.7"
|
||||
gem "rspec", "~> 2.10"
|
||||
gem "guard"
|
||||
gem "guard-rspec"
|
||||
gem "rb-readline", "~> 0.5.0"
|
||||
gem "jeweler", ">= 1.6.2"
|
||||
#gem "simplecov"
|
||||
gem 'capture-output', '~> 1.0.0'
|
||||
gem 'coveralls', require: false
|
||||
gem "test_construct"
|
||||
gem "capture-output", "~> 1.0.0"
|
||||
if RbConfig::CONFIG['host_os'] =~ /linux|freebsd|openbsd|sunos|solaris/
|
||||
gem 'guard'
|
||||
gem 'guard-rspec'
|
||||
gem 'jeweler', '>= 1.6.2', '< 2.2' if this_ruby < ruby_230
|
||||
gem 'jeweler', '>= 1.6.2' if this_ruby >= ruby_230
|
||||
gem 'rake', '>= 0.8.7'
|
||||
gem 'rb-readline', '~> 0.5.0'
|
||||
gem 'rspec', '~> 3.5.0'
|
||||
gem 'rubocop'
|
||||
gem 'test_construct'
|
||||
|
||||
install_if -> { RUBY_PLATFORM =~ /linux|freebsd|openbsd|sunos|solaris/ } do
|
||||
gem 'libnotify'
|
||||
end
|
||||
if RUBY_VERSION >= '1.9.2'
|
||||
gem "rubocop"
|
||||
|
||||
install_if -> { RUBY_PLATFORM =~ /darwin/ } do
|
||||
gem 'terminal-notifier-guard', '~> 1.7.0'
|
||||
end
|
||||
|
||||
install_if -> { this_ruby < ruby_230 } do
|
||||
gem 'listen', '< 3'
|
||||
gem 'rack', '< 2'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
# homesick
|
||||
|
||||
[](http://badge.fury.io/rb/homesick)
|
||||
[](https://travis-ci.org/technicalpickles/homesick)
|
||||
[](https://gemnasium.com/technicalpickles/homesick)
|
||||
[](http://badge.fury.io/rb/homesick)
|
||||
[](https://travis-ci.org/technicalpickles/homesick)
|
||||
[](https://gemnasium.com/technicalpickles/homesick)
|
||||
[](https://coveralls.io/r/technicalpickles/homesick)
|
||||
[](https://codeclimate.com/github/technicalpickles/homesick)
|
||||
[](https://gitter.im/technicalpickles/homesick)
|
||||
[](https://codeclimate.com/github/technicalpickles/homesick)
|
||||
[](https://gitter.im/technicalpickles/homesick)
|
||||
|
||||
Your home directory is your castle. Don't leave your dotfiles behind.
|
||||
|
||||
@@ -40,7 +40,7 @@ If you need to add further configuration steps you can add these in a file calle
|
||||
|
||||
homesick rc CASTLE
|
||||
|
||||
The contents of the .homesickrc file must be valid Ruby code as the file will be executed with Ruby's eval construct. The .homesickrc is also passed the current homesick object during its execution and this is available within the .homesickrc file as the 'self' variable.
|
||||
The contents of the .homesickrc file must be valid Ruby code as the file will be executed with Ruby's eval construct. The .homesickrc is also passed the current homesick object during its execution and this is available within the .homesickrc file as the 'self' variable. As the rc operation can be destructive the command normally asks for confirmation before proceeding. You can bypass this by passing the '--force' option, for example `homesick rc --force CASTLE`.
|
||||
|
||||
If you're not sure what castles you have around, you can easily list them:
|
||||
|
||||
@@ -164,9 +164,9 @@ and castle
|
||||
|
||||
Homesick is tested on the following Ruby versions:
|
||||
|
||||
* 1.9.3
|
||||
* 2.0.0
|
||||
* 2.1.0
|
||||
* 2.2.6
|
||||
* 2.3.3
|
||||
* 2.4.0
|
||||
|
||||
## Note on Patches/Pull Requests
|
||||
|
||||
|
||||
107
homesick.gemspec
107
homesick.gemspec
@@ -2,19 +2,19 @@
|
||||
# DO NOT EDIT THIS FILE DIRECTLY
|
||||
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
||||
# -*- encoding: utf-8 -*-
|
||||
# stub: homesick 1.1.0 ruby lib
|
||||
# stub: homesick 1.1.5 ruby lib
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = "homesick"
|
||||
s.version = "1.1.0"
|
||||
s.name = "homesick".freeze
|
||||
s.version = "1.1.5"
|
||||
|
||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||
s.require_paths = ["lib"]
|
||||
s.authors = ["Joshua Nichols", "Yusuke Murata"]
|
||||
s.date = "2014-04-28"
|
||||
s.description = "\n Your home directory is your castle. Don't leave your dotfiles behind.\n \n\n Homesick is sorta like rip, but for dotfiles. It uses git to clone a repository containing dotfiles, and saves them in ~/.homesick. It then allows you to symlink all the dotfiles into place with a single command. \n\n "
|
||||
s.email = ["josh@technicalpickles.com", "info@muratayusuke.com"]
|
||||
s.executables = ["homesick"]
|
||||
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
||||
s.require_paths = ["lib".freeze]
|
||||
s.authors = ["Joshua Nichols".freeze, "Yusuke Murata".freeze]
|
||||
s.date = "2017-03-23"
|
||||
s.description = "\n Your home directory is your castle. Don't leave your dotfiles behind.\n \n\n Homesick is sorta like rip, but for dotfiles. It uses git to clone a repository containing dotfiles, and saves them in ~/.homesick. It then allows you to symlink all the dotfiles into place with a single command. \n\n ".freeze
|
||||
s.email = ["josh@technicalpickles.com".freeze, "info@muratayusuke.com".freeze]
|
||||
s.executables = ["homesick".freeze]
|
||||
s.extra_rdoc_files = [
|
||||
"ChangeLog.markdown",
|
||||
"LICENSE",
|
||||
@@ -37,58 +37,69 @@ Gem::Specification.new do |s|
|
||||
"lib/homesick/actions/file_actions.rb",
|
||||
"lib/homesick/actions/git_actions.rb",
|
||||
"lib/homesick/cli.rb",
|
||||
"lib/homesick/shell.rb",
|
||||
"lib/homesick/utils.rb",
|
||||
"lib/homesick/version.rb",
|
||||
"spec/homesick_cli_spec.rb",
|
||||
"spec/spec.opts",
|
||||
"spec/spec_helper.rb"
|
||||
]
|
||||
s.homepage = "http://github.com/technicalpickles/homesick"
|
||||
s.licenses = ["MIT"]
|
||||
s.rubygems_version = "2.2.2"
|
||||
s.summary = "Your home directory is your castle. Don't leave your dotfiles behind."
|
||||
s.homepage = "http://github.com/technicalpickles/homesick".freeze
|
||||
s.licenses = ["MIT".freeze]
|
||||
s.rubygems_version = "2.6.11".freeze
|
||||
s.summary = "Your home directory is your castle. Don't leave your dotfiles behind.".freeze
|
||||
|
||||
if s.respond_to? :specification_version then
|
||||
s.specification_version = 4
|
||||
|
||||
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
||||
s.add_runtime_dependency(%q<thor>, [">= 0.14.0"])
|
||||
s.add_development_dependency(%q<rake>, [">= 0.8.7"])
|
||||
s.add_development_dependency(%q<rspec>, ["~> 2.10"])
|
||||
s.add_development_dependency(%q<guard>, [">= 0"])
|
||||
s.add_development_dependency(%q<guard-rspec>, [">= 0"])
|
||||
s.add_development_dependency(%q<rb-readline>, ["~> 0.5.0"])
|
||||
s.add_development_dependency(%q<jeweler>, [">= 1.6.2"])
|
||||
s.add_development_dependency(%q<coveralls>, [">= 0"])
|
||||
s.add_development_dependency(%q<test_construct>, [">= 0"])
|
||||
s.add_development_dependency(%q<capture-output>, ["~> 1.0.0"])
|
||||
s.add_development_dependency(%q<rubocop>, [">= 0"])
|
||||
s.add_runtime_dependency(%q<thor>.freeze, [">= 0.14.0"])
|
||||
s.add_development_dependency(%q<capture-output>.freeze, ["~> 1.0.0"])
|
||||
s.add_development_dependency(%q<coveralls>.freeze, [">= 0"])
|
||||
s.add_development_dependency(%q<guard>.freeze, [">= 0"])
|
||||
s.add_development_dependency(%q<guard-rspec>.freeze, [">= 0"])
|
||||
s.add_development_dependency(%q<jeweler>.freeze, [">= 1.6.2"])
|
||||
s.add_development_dependency(%q<rake>.freeze, [">= 0.8.7"])
|
||||
s.add_development_dependency(%q<rb-readline>.freeze, ["~> 0.5.0"])
|
||||
s.add_development_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
|
||||
s.add_development_dependency(%q<rubocop>.freeze, [">= 0"])
|
||||
s.add_development_dependency(%q<test_construct>.freeze, [">= 0"])
|
||||
s.add_development_dependency(%q<libnotify>.freeze, [">= 0"])
|
||||
s.add_development_dependency(%q<terminal-notifier-guard>.freeze, ["~> 1.7.0"])
|
||||
s.add_development_dependency(%q<listen>.freeze, ["< 3"])
|
||||
s.add_development_dependency(%q<rack>.freeze, ["< 2"])
|
||||
else
|
||||
s.add_dependency(%q<thor>, [">= 0.14.0"])
|
||||
s.add_dependency(%q<rake>, [">= 0.8.7"])
|
||||
s.add_dependency(%q<rspec>, ["~> 2.10"])
|
||||
s.add_dependency(%q<guard>, [">= 0"])
|
||||
s.add_dependency(%q<guard-rspec>, [">= 0"])
|
||||
s.add_dependency(%q<rb-readline>, ["~> 0.5.0"])
|
||||
s.add_dependency(%q<jeweler>, [">= 1.6.2"])
|
||||
s.add_dependency(%q<coveralls>, [">= 0"])
|
||||
s.add_dependency(%q<test_construct>, [">= 0"])
|
||||
s.add_dependency(%q<capture-output>, ["~> 1.0.0"])
|
||||
s.add_dependency(%q<rubocop>, [">= 0"])
|
||||
s.add_dependency(%q<thor>.freeze, [">= 0.14.0"])
|
||||
s.add_dependency(%q<capture-output>.freeze, ["~> 1.0.0"])
|
||||
s.add_dependency(%q<coveralls>.freeze, [">= 0"])
|
||||
s.add_dependency(%q<guard>.freeze, [">= 0"])
|
||||
s.add_dependency(%q<guard-rspec>.freeze, [">= 0"])
|
||||
s.add_dependency(%q<jeweler>.freeze, [">= 1.6.2"])
|
||||
s.add_dependency(%q<rake>.freeze, [">= 0.8.7"])
|
||||
s.add_dependency(%q<rb-readline>.freeze, ["~> 0.5.0"])
|
||||
s.add_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
|
||||
s.add_dependency(%q<rubocop>.freeze, [">= 0"])
|
||||
s.add_dependency(%q<test_construct>.freeze, [">= 0"])
|
||||
s.add_dependency(%q<libnotify>.freeze, [">= 0"])
|
||||
s.add_dependency(%q<terminal-notifier-guard>.freeze, ["~> 1.7.0"])
|
||||
s.add_dependency(%q<listen>.freeze, ["< 3"])
|
||||
s.add_dependency(%q<rack>.freeze, ["< 2"])
|
||||
end
|
||||
else
|
||||
s.add_dependency(%q<thor>, [">= 0.14.0"])
|
||||
s.add_dependency(%q<rake>, [">= 0.8.7"])
|
||||
s.add_dependency(%q<rspec>, ["~> 2.10"])
|
||||
s.add_dependency(%q<guard>, [">= 0"])
|
||||
s.add_dependency(%q<guard-rspec>, [">= 0"])
|
||||
s.add_dependency(%q<rb-readline>, ["~> 0.5.0"])
|
||||
s.add_dependency(%q<jeweler>, [">= 1.6.2"])
|
||||
s.add_dependency(%q<coveralls>, [">= 0"])
|
||||
s.add_dependency(%q<test_construct>, [">= 0"])
|
||||
s.add_dependency(%q<capture-output>, ["~> 1.0.0"])
|
||||
s.add_dependency(%q<rubocop>, [">= 0"])
|
||||
s.add_dependency(%q<thor>.freeze, [">= 0.14.0"])
|
||||
s.add_dependency(%q<capture-output>.freeze, ["~> 1.0.0"])
|
||||
s.add_dependency(%q<coveralls>.freeze, [">= 0"])
|
||||
s.add_dependency(%q<guard>.freeze, [">= 0"])
|
||||
s.add_dependency(%q<guard-rspec>.freeze, [">= 0"])
|
||||
s.add_dependency(%q<jeweler>.freeze, [">= 1.6.2"])
|
||||
s.add_dependency(%q<rake>.freeze, [">= 0.8.7"])
|
||||
s.add_dependency(%q<rb-readline>.freeze, ["~> 0.5.0"])
|
||||
s.add_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
|
||||
s.add_dependency(%q<rubocop>.freeze, [">= 0"])
|
||||
s.add_dependency(%q<test_construct>.freeze, [">= 0"])
|
||||
s.add_dependency(%q<libnotify>.freeze, [">= 0"])
|
||||
s.add_dependency(%q<terminal-notifier-guard>.freeze, ["~> 1.7.0"])
|
||||
s.add_dependency(%q<listen>.freeze, ["< 3"])
|
||||
s.add_dependency(%q<rack>.freeze, ["< 2"])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
require 'homesick/shell'
|
||||
require 'homesick/actions/file_actions'
|
||||
require 'homesick/actions/git_actions'
|
||||
require 'homesick/version'
|
||||
@@ -8,7 +7,7 @@ require 'homesick/cli'
|
||||
|
||||
# Homesick's top-level module
|
||||
module Homesick
|
||||
GITHUB_NAME_REPO_PATTERN = /\A([A-Za-z0-9_-]+\/[A-Za-z0-9_-]+)\Z/
|
||||
GITHUB_NAME_REPO_PATTERN = %r{\A([A-Za-z0-9_-]+/[A-Za-z0-9_-]+)\Z}
|
||||
SUBDIR_FILENAME = '.homesick_subdir'
|
||||
|
||||
DEFAULT_CASTLE_NAME = 'dotfiles'
|
||||
|
||||
@@ -3,16 +3,14 @@ module Homesick
|
||||
module Actions
|
||||
# File-related helper methods for Homesick
|
||||
module FileActions
|
||||
def mv(source, destination, config = {})
|
||||
def mv(source, destination)
|
||||
source = Pathname.new(source)
|
||||
destination = Pathname.new(destination + source.basename)
|
||||
|
||||
if destination.exist?
|
||||
case
|
||||
when destination.exist? && (options[:force] || shell.file_collision(destination) { source })
|
||||
say_status :conflict, "#{destination} exists", :red
|
||||
|
||||
FileUtils.mv source, destination if (options[:force] || shell.file_collision(destination) { source }) && !options[:pretend]
|
||||
FileUtils.mv source, destination unless options[:pretend]
|
||||
else
|
||||
# this needs some sort of message here.
|
||||
FileUtils.mv source, destination unless options[:pretend]
|
||||
end
|
||||
end
|
||||
@@ -43,8 +41,8 @@ module Homesick
|
||||
FileUtils.rm_r dir
|
||||
end
|
||||
|
||||
def ln_s(source, destination, config = {})
|
||||
source = Pathname.new(source)
|
||||
def ln_s(source, destination)
|
||||
source = Pathname.new(source).realpath
|
||||
destination = Pathname.new(destination)
|
||||
FileUtils.mkdir_p destination.dirname
|
||||
|
||||
@@ -65,17 +63,15 @@ module Homesick
|
||||
case action
|
||||
when :identical
|
||||
say_status :identical, destination.expand_path, :blue
|
||||
when :symlink_conflict
|
||||
when :symlink_conflict, :conflict
|
||||
if action == :conflict
|
||||
say_status :conflict, "#{destination} exists", :red
|
||||
else
|
||||
say_status :conflict,
|
||||
"#{destination} exists and points to #{destination.readlink}",
|
||||
:red
|
||||
|
||||
FileUtils.rm destination
|
||||
FileUtils.ln_s source, destination, force: true unless options[:pretend]
|
||||
when :conflict
|
||||
say_status :conflict, "#{destination} exists", :red
|
||||
|
||||
if collision_accepted?(destination)
|
||||
end
|
||||
if collision_accepted?(destination, source)
|
||||
FileUtils.rm_r destination, force: true unless options[:pretend]
|
||||
FileUtils.ln_s source, destination, force: true unless options[:pretend]
|
||||
end
|
||||
|
||||
@@ -3,12 +3,31 @@ module Homesick
|
||||
module Actions
|
||||
# Git-related helper methods for Homesick
|
||||
module GitActions
|
||||
# Information on the minimum git version required for Homesick
|
||||
MIN_VERSION = {
|
||||
major: 1,
|
||||
minor: 8,
|
||||
patch: 0
|
||||
}
|
||||
STRING = MIN_VERSION.values.join('.')
|
||||
|
||||
def git_version_correct?
|
||||
info = `git --version`.scan(/(\d+)\.(\d+)\.(\d+)/).flatten.map(&:to_i)
|
||||
return false unless info.count == 3
|
||||
current_version = Hash[[:major, :minor, :patch].zip(info)]
|
||||
return true if current_version.eql?(MIN_VERSION)
|
||||
return true if current_version[:major] > MIN_VERSION[:major]
|
||||
return true if current_version[:major] == MIN_VERSION[:major] && current_version[:minor] > MIN_VERSION[:minor]
|
||||
return true if current_version[:major] == MIN_VERSION[:major] && current_version[:minor] == MIN_VERSION[:minor] && current_version[:patch] >= MIN_VERSION[:patch]
|
||||
false
|
||||
end
|
||||
|
||||
# TODO: move this to be more like thor's template, empty_directory, etc
|
||||
def git_clone(repo, config = {})
|
||||
config ||= {}
|
||||
destination = config[:destination] || File.basename(repo, '.git')
|
||||
|
||||
destination = Pathname.new(destination) unless destination.kind_of?(Pathname)
|
||||
destination = Pathname.new(destination) unless destination.is_a?(Pathname)
|
||||
FileUtils.mkdir_p destination.dirname
|
||||
|
||||
if destination.directory?
|
||||
@@ -46,22 +65,22 @@ module Homesick
|
||||
end
|
||||
end
|
||||
|
||||
def git_submodule_init(config = {})
|
||||
def git_submodule_init
|
||||
say_status 'git submodule', 'init', :green
|
||||
system 'git submodule --quiet init'
|
||||
end
|
||||
|
||||
def git_submodule_update(config = {})
|
||||
def git_submodule_update
|
||||
say_status 'git submodule', 'update', :green
|
||||
system 'git submodule --quiet update --init --recursive >/dev/null 2>&1'
|
||||
end
|
||||
|
||||
def git_pull(config = {})
|
||||
def git_pull
|
||||
say_status 'git pull', '', :green
|
||||
system 'git pull --quiet'
|
||||
end
|
||||
|
||||
def git_push(config = {})
|
||||
def git_push
|
||||
say_status 'git push', '', :green
|
||||
system 'git push'
|
||||
end
|
||||
@@ -69,23 +88,23 @@ module Homesick
|
||||
def git_commit_all(config = {})
|
||||
say_status 'git commit all', '', :green
|
||||
if config[:message]
|
||||
system "git commit -a -m '#{config[:message]}'"
|
||||
system %(git commit -a -m "#{config[:message]}")
|
||||
else
|
||||
system 'git commit -v -a'
|
||||
end
|
||||
end
|
||||
|
||||
def git_add(file, config = {})
|
||||
def git_add(file)
|
||||
say_status 'git add file', '', :green
|
||||
system "git add '#{file}'"
|
||||
end
|
||||
|
||||
def git_status(config = {})
|
||||
def git_status
|
||||
say_status 'git status', '', :green
|
||||
system 'git status'
|
||||
end
|
||||
|
||||
def git_diff(config = {})
|
||||
def git_diff
|
||||
say_status 'git diff', '', :green
|
||||
system 'git diff'
|
||||
end
|
||||
|
||||
@@ -19,27 +19,43 @@ module Homesick
|
||||
|
||||
def initialize(args = [], options = {}, config = {})
|
||||
super
|
||||
self.shell = Homesick::Shell.new
|
||||
# Check if git is installed
|
||||
unless git_version_correct?
|
||||
say_status :error, "Git version >= #{Homesick::Actions::GitActions::STRING} must be installed to use Homesick", :red
|
||||
exit(1)
|
||||
end
|
||||
# Hack in support for diffing symlinks
|
||||
# Also adds support for checking if destination or content is a directory
|
||||
shell_metaclass = class << shell; self; end
|
||||
shell_metaclass.send(:define_method, :show_diff) do |destination, content|
|
||||
destination = Pathname.new(destination)
|
||||
content = Pathname.new(content)
|
||||
return 'Unable to create diff: destination or content is a directory' if destination.directory? || content.directory?
|
||||
return super(destination, content) unless destination.symlink?
|
||||
say "- #{destination.readlink}", :red, true
|
||||
say "+ #{content.expand_path}", :green, true
|
||||
end
|
||||
end
|
||||
|
||||
desc 'clone URI', 'Clone +uri+ as a castle for homesick'
|
||||
def clone(uri)
|
||||
desc 'clone URI CASTLE_NAME', 'Clone +uri+ as a castle with name CASTLE_NAME for homesick'
|
||||
def clone(uri, destination=nil)
|
||||
destination = Pathname.new(destination) unless destination.nil?
|
||||
|
||||
inside repos_dir do
|
||||
destination = nil
|
||||
if File.exist?(uri)
|
||||
uri = Pathname.new(uri).expand_path
|
||||
fail "Castle already cloned to #{uri}" if uri.to_s.start_with?(repos_dir.to_s)
|
||||
|
||||
destination = uri.basename
|
||||
destination = uri.basename if destination.nil?
|
||||
|
||||
ln_s uri, destination
|
||||
elsif uri =~ GITHUB_NAME_REPO_PATTERN
|
||||
destination = Pathname.new(uri).basename
|
||||
destination = Pathname.new(uri).basename if destination.nil?
|
||||
git_clone "https://github.com/#{Regexp.last_match[1]}.git",
|
||||
destination: destination
|
||||
elsif uri =~ /%r([^%r]*?)(\.git)?\Z/ || uri =~ /[^:]+:([^:]+)(\.git)?\Z/
|
||||
destination = Pathname.new(Regexp.last_match[1])
|
||||
git_clone uri
|
||||
destination = Pathname.new(Regexp.last_match[1].gsub(/\.git$/, '')).basename if destination.nil?
|
||||
git_clone uri, destination: destination
|
||||
else
|
||||
fail "Unknown URI format: #{uri}"
|
||||
end
|
||||
@@ -49,23 +65,21 @@ module Homesick
|
||||
end
|
||||
|
||||
desc 'rc CASTLE', 'Run the .homesickrc for the specified castle'
|
||||
method_option :force,
|
||||
type: :boolean,
|
||||
default: false,
|
||||
desc: 'Evaluate .homesickrc without prompting.'
|
||||
def rc(name = DEFAULT_CASTLE_NAME)
|
||||
inside repos_dir do
|
||||
destination = Pathname.new(name)
|
||||
homesickrc = destination.join('.homesickrc').expand_path
|
||||
if homesickrc.exist?
|
||||
proceed = shell.yes?("#{name} has a .homesickrc. Proceed with evaling it? (This could be destructive)")
|
||||
if proceed
|
||||
return unless homesickrc.exist?
|
||||
proceed = options[:force] || shell.yes?("#{name} has a .homesickrc. Proceed with evaling it? (This could be destructive)")
|
||||
return say_status 'eval skip', "not evaling #{homesickrc}, #{destination} may need manual configuration", :blue unless proceed
|
||||
say_status 'eval', homesickrc
|
||||
inside destination do
|
||||
eval homesickrc.read, binding, homesickrc.expand_path.to_s
|
||||
end
|
||||
else
|
||||
say_status 'eval skip',
|
||||
"not evaling #{homesickrc}, #{destination} may need manual configuration",
|
||||
:blue
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -115,6 +129,7 @@ module Homesick
|
||||
|
||||
desc 'link CASTLE', 'Symlinks all dotfiles from the specified castle'
|
||||
method_option :force,
|
||||
type: :boolean,
|
||||
default: false,
|
||||
desc: 'Overwrite existing conflicting symlinks without prompting.'
|
||||
def link(name = DEFAULT_CASTLE_NAME)
|
||||
@@ -232,12 +247,11 @@ module Homesick
|
||||
desc 'destroy CASTLE', 'Delete all symlinks and remove the cloned repository'
|
||||
def destroy(name)
|
||||
check_castle_existance name, 'destroy'
|
||||
return unless shell.yes?('This will destroy your castle irreversible! Are you sure?')
|
||||
|
||||
if shell.yes?('This will destroy your castle irreversible! Are you sure?')
|
||||
unlink(name)
|
||||
rm_rf repos_dir.join(name)
|
||||
end
|
||||
end
|
||||
|
||||
desc 'cd CASTLE', 'Open a new shell in the root of the given castle'
|
||||
def cd(castle = DEFAULT_CASTLE_NAME)
|
||||
@@ -263,11 +277,11 @@ module Homesick
|
||||
end
|
||||
check_castle_existance castle, 'open'
|
||||
castle_dir = repos_dir.join(castle)
|
||||
say_status "#{ENV['EDITOR']} #{castle_dir.realpath}",
|
||||
say_status "#{castle_dir.realpath}: #{ENV['EDITOR']} .",
|
||||
"Opening the root directory of castle '#{castle}' in editor '#{ENV['EDITOR']}'.",
|
||||
:green
|
||||
inside castle_dir do
|
||||
system(ENV['EDITOR'])
|
||||
system("#{ENV['EDITOR']} .")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
require 'thor'
|
||||
|
||||
module Homesick
|
||||
# Hack in support for diffing symlinks
|
||||
class Shell < Thor::Shell::Color
|
||||
def show_diff(destination, content)
|
||||
destination = Pathname.new(destination)
|
||||
|
||||
if destination.symlink?
|
||||
say "- #{destination.readlink}", :red, true
|
||||
say "+ #{content.expand_path}", :green, true
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,10 +1,12 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
require 'pathname'
|
||||
|
||||
module Homesick
|
||||
# Various utility methods that are used by Homesick
|
||||
module Utils
|
||||
QUIETABLE = ['say_status']
|
||||
QUIETABLE = [:say_status]
|
||||
|
||||
PRETENDABLE = ['system']
|
||||
PRETENDABLE = [:system]
|
||||
|
||||
QUIETABLE.each do |method_name|
|
||||
define_method(method_name) do |*args|
|
||||
@@ -21,7 +23,7 @@ module Homesick
|
||||
protected
|
||||
|
||||
def home_dir
|
||||
@home_dir ||= Pathname.new(ENV['HOME'] || '~').expand_path
|
||||
@home_dir ||= Pathname.new(ENV['HOME'] || '~').realpath
|
||||
end
|
||||
|
||||
def repos_dir
|
||||
@@ -33,13 +35,12 @@ module Homesick
|
||||
end
|
||||
|
||||
def check_castle_existance(name, action)
|
||||
unless castle_dir(name).exist?
|
||||
return if castle_dir(name).exist?
|
||||
say_status :error,
|
||||
"Could not #{action} #{name}, expected #{castle_dir(name)} exist and contain dotfiles",
|
||||
:red
|
||||
exit(1)
|
||||
end
|
||||
end
|
||||
|
||||
def all_castles
|
||||
dirs = Pathname.glob("#{repos_dir}/**/.git", File::FNM_DOTMATCH)
|
||||
@@ -51,7 +52,7 @@ module Homesick
|
||||
end
|
||||
end
|
||||
|
||||
def inside_each_castle(&block)
|
||||
def inside_each_castle
|
||||
all_castles.each do |git_dir|
|
||||
castle = git_dir.dirname
|
||||
Dir.chdir castle do # so we can call git config from the right contxt
|
||||
@@ -128,7 +129,6 @@ module Homesick
|
||||
def move_dir_contents(target, dir_path)
|
||||
child_files = dir_path.children
|
||||
child_files.each do |child|
|
||||
|
||||
target_path = target.join(child.basename)
|
||||
if target_path.exist?
|
||||
if more_recent?(child, target_path) && target.file?
|
||||
@@ -148,9 +148,9 @@ module Homesick
|
||||
first_p.mtime > second_p.mtime && !first_p.symlink?
|
||||
end
|
||||
|
||||
def collision_accepted?(destination)
|
||||
fail "Argument must be an instance of Pathname, #{destination.class.name} given" unless destination.instance_of?(Pathname)
|
||||
options[:force] || shell.file_collision(destination) { source }
|
||||
def collision_accepted?(destination, source)
|
||||
fail "Arguments must be instances of Pathname, #{destination.class.name} and #{source.class.name} given" unless destination.instance_of?(Pathname) && source.instance_of?(Pathname)
|
||||
options[:force] || shell.file_collision(destination) { File.binread(source) }
|
||||
end
|
||||
|
||||
def each_file(castle, basedir, subdirs)
|
||||
@@ -191,7 +191,7 @@ module Homesick
|
||||
end
|
||||
|
||||
def unsymlink_each(castle, basedir, subdirs)
|
||||
each_file(castle, basedir, subdirs) do |absolute_path, home_path|
|
||||
each_file(castle, basedir, subdirs) do |_absolute_path, home_path|
|
||||
rm_link home_path
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ module Homesick
|
||||
module Version
|
||||
MAJOR = 1
|
||||
MINOR = 1
|
||||
PATCH = 0
|
||||
PATCH = 5
|
||||
|
||||
STRING = [MAJOR, MINOR, PATCH].compact.join('.')
|
||||
end
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
require 'spec_helper'
|
||||
require 'capture-output'
|
||||
require 'pathname'
|
||||
|
||||
describe Homesick::CLI do
|
||||
let(:home) { create_construct }
|
||||
@@ -12,6 +13,48 @@ describe Homesick::CLI do
|
||||
|
||||
before { allow(homesick).to receive(:repos_dir).and_return(castles) }
|
||||
|
||||
describe 'smoke tests' do
|
||||
context 'when running bin/homesick' do
|
||||
before do
|
||||
bin_path = Pathname.new(__FILE__).parent.parent
|
||||
@output = `#{bin_path.expand_path}/bin/homesick`
|
||||
end
|
||||
it 'should output some text when bin/homesick is called' do
|
||||
expect(@output.length).to be > 0
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a git version that doesn\'t meet the minimum required is installed' do
|
||||
before do
|
||||
expect_any_instance_of(Homesick::Actions::GitActions).to receive(:`).and_return('git version 1.7.6')
|
||||
end
|
||||
it 'should raise an exception' do
|
||||
output = Capture.stdout { expect { Homesick::CLI.new }.to raise_error SystemExit }
|
||||
expect(output.chomp).to include(Homesick::Actions::GitActions::STRING)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a git version that is the same as the minimum required is installed' do
|
||||
before do
|
||||
expect_any_instance_of(Homesick::Actions::GitActions).to receive(:`).at_least(:once).and_return("git version #{Homesick::Actions::GitActions::STRING}")
|
||||
end
|
||||
it 'should not raise an exception' do
|
||||
output = Capture.stdout { expect { Homesick::CLI.new }.not_to raise_error }
|
||||
expect(output.chomp).not_to include(Homesick::Actions::GitActions::STRING)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a git version that is greater than the minimum required is installed' do
|
||||
before do
|
||||
expect_any_instance_of(Homesick::Actions::GitActions).to receive(:`).at_least(:once).and_return('git version 3.9.8')
|
||||
end
|
||||
it 'should not raise an exception' do
|
||||
output = Capture.stdout { expect { Homesick::CLI.new }.not_to raise_error }
|
||||
expect(output.chomp).not_to include(Homesick::Actions::GitActions::STRING)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'clone' do
|
||||
context 'has a .homesickrc' do
|
||||
it 'runs the .homesickrc' do
|
||||
@@ -63,55 +106,63 @@ describe Homesick::CLI do
|
||||
homesick.clone "file://#{bare_repo}"
|
||||
end
|
||||
expect(File.directory?(File.join(home.to_s, '.homesick/repos/dotfiles')))
|
||||
.to be_true
|
||||
.to be_truthy
|
||||
end
|
||||
|
||||
it 'clones git repo like git://host/path/to.git' do
|
||||
expect(homesick).to receive(:git_clone)
|
||||
.with('git://github.com/technicalpickles/pickled-vim.git')
|
||||
.with('git://github.com/technicalpickles/pickled-vim.git', destination: Pathname.new('pickled-vim'))
|
||||
|
||||
homesick.clone 'git://github.com/technicalpickles/pickled-vim.git'
|
||||
end
|
||||
|
||||
it 'clones git repo like git@host:path/to.git' do
|
||||
expect(homesick).to receive(:git_clone)
|
||||
.with('git@github.com:technicalpickles/pickled-vim.git')
|
||||
.with('git@github.com:technicalpickles/pickled-vim.git', destination: Pathname.new('pickled-vim'))
|
||||
|
||||
homesick.clone 'git@github.com:technicalpickles/pickled-vim.git'
|
||||
end
|
||||
|
||||
it 'clones git repo like http://host/path/to.git' do
|
||||
expect(homesick).to receive(:git_clone)
|
||||
.with('http://github.com/technicalpickles/pickled-vim.git')
|
||||
.with('http://github.com/technicalpickles/pickled-vim.git', destination: Pathname.new('pickled-vim'))
|
||||
|
||||
homesick.clone 'http://github.com/technicalpickles/pickled-vim.git'
|
||||
end
|
||||
|
||||
it 'clones git repo like http://host/path/to' do
|
||||
expect(homesick).to receive(:git_clone)
|
||||
.with('http://github.com/technicalpickles/pickled-vim')
|
||||
.with('http://github.com/technicalpickles/pickled-vim', destination: Pathname.new('pickled-vim'))
|
||||
|
||||
homesick.clone 'http://github.com/technicalpickles/pickled-vim'
|
||||
end
|
||||
|
||||
it 'clones git repo like host-alias:repos.git' do
|
||||
expect(homesick).to receive(:git_clone).with('gitolite:pickled-vim.git')
|
||||
expect(homesick).to receive(:git_clone).with('gitolite:pickled-vim.git',
|
||||
destination: Pathname.new('pickled-vim'))
|
||||
|
||||
homesick.clone 'gitolite:pickled-vim.git'
|
||||
end
|
||||
|
||||
it 'throws an exception when trying to clone a malformed uri like malformed' do
|
||||
expect(homesick).not_to receive(:git_clone)
|
||||
expect { homesick.clone 'malformed' }.to raise_error
|
||||
expect { homesick.clone 'malformed' }.to raise_error(RuntimeError)
|
||||
end
|
||||
|
||||
it 'clones a github repo' do
|
||||
expect(homesick).to receive(:git_clone)
|
||||
.with('https://github.com/wfarr/dotfiles.git',
|
||||
destination: Pathname.new('dotfiles'))
|
||||
.with('https://github.com/wfarr/dotfiles.git', destination: Pathname.new('dotfiles'))
|
||||
|
||||
homesick.clone 'wfarr/dotfiles'
|
||||
end
|
||||
|
||||
it 'accepts a destination', :focus do
|
||||
expect(homesick).to receive(:git_clone)
|
||||
.with('https://github.com/wfarr/dotfiles.git',
|
||||
destination: Pathname.new('other-name'))
|
||||
|
||||
homesick.clone 'wfarr/dotfiles', 'other-name'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'rc' do
|
||||
@@ -136,6 +187,26 @@ describe Homesick::CLI do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when options[:force] == true' do
|
||||
let(:homesick) { Homesick::CLI.new [], force: true }
|
||||
before do
|
||||
expect_any_instance_of(Thor::Shell::Basic).to_not receive(:yes?)
|
||||
end
|
||||
|
||||
it 'executes the .homesickrc' do
|
||||
castle.file('.homesickrc') do |file|
|
||||
file << "File.open(Dir.pwd + '/testing', 'w') do |f|
|
||||
f.print 'testing'
|
||||
end"
|
||||
end
|
||||
|
||||
expect(homesick).to receive(:say_status).with('eval', kind_of(Pathname))
|
||||
homesick.rc castle
|
||||
|
||||
expect(castle.join('testing')).to exist
|
||||
end
|
||||
end
|
||||
|
||||
context 'when told not to do so' do
|
||||
before do
|
||||
expect_any_instance_of(Thor::Shell::Basic).to receive(:yes?).with(be_a(String)).and_return(false)
|
||||
@@ -156,7 +227,7 @@ describe Homesick::CLI do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'link' do
|
||||
describe 'link_castle' do
|
||||
let(:castle) { given_castle('glencairn') }
|
||||
|
||||
it 'links dotfiles from a castle to the home folder' do
|
||||
@@ -244,11 +315,9 @@ describe Homesick::CLI do
|
||||
home_config_dir = home.join('.config')
|
||||
home_someapp_dir = home_config_dir.join('someapp')
|
||||
expect(home_config_dir.symlink?).to eq(false)
|
||||
expect(home_config_dir.join('.some_dotfile').readlink)
|
||||
.to eq(config_dotfile)
|
||||
expect(home_config_dir.join('.some_dotfile').readlink).to eq(config_dotfile)
|
||||
expect(home_someapp_dir.symlink?).to eq(false)
|
||||
expect(home_someapp_dir.join('.some_appfile').readlink)
|
||||
.to eq(someapp_dotfile)
|
||||
expect(home_someapp_dir.join('.some_appfile').readlink).to eq(someapp_dotfile)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -357,13 +426,9 @@ describe Homesick::CLI do
|
||||
given_castle('wtf/zomg')
|
||||
|
||||
expect(homesick).to receive(:say_status)
|
||||
.with('zomg',
|
||||
'git://github.com/technicalpickles/zomg.git',
|
||||
:cyan)
|
||||
.with('zomg', 'git://github.com/technicalpickles/zomg.git', :cyan)
|
||||
expect(homesick).to receive(:say_status)
|
||||
.with('wtf/zomg',
|
||||
'git://github.com/technicalpickles/zomg.git',
|
||||
:cyan)
|
||||
.with('wtf/zomg', 'git://github.com/technicalpickles/zomg.git', :cyan)
|
||||
|
||||
homesick.list
|
||||
end
|
||||
@@ -373,7 +438,7 @@ describe Homesick::CLI do
|
||||
it 'says "nothing to commit" when there are no changes' do
|
||||
given_castle('castle_repo')
|
||||
text = Capture.stdout { homesick.status('castle_repo') }
|
||||
expect(text).to match(/nothing to commit \(create\/copy files and use "git add" to track\)$/)
|
||||
expect(text).to match(%r{nothing to commit \(create/copy files and use "git add" to track\)$})
|
||||
end
|
||||
|
||||
it 'says "Changes to be committed" when there are changes' do
|
||||
@@ -381,9 +446,7 @@ describe Homesick::CLI do
|
||||
some_rc_file = home.file '.some_rc_file'
|
||||
homesick.track(some_rc_file.to_s, 'castle_repo')
|
||||
text = Capture.stdout { homesick.status('castle_repo') }
|
||||
expect(text).to match(
|
||||
/Changes to be committed:.*new file:\s*home\/.some_rc_file/m
|
||||
)
|
||||
expect(text).to match(%r{Changes to be committed:.*new file:\s*home\/.some_rc_file}m)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -455,7 +518,6 @@ describe Homesick::CLI do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'push' do
|
||||
@@ -467,9 +529,7 @@ describe Homesick::CLI do
|
||||
|
||||
it 'prints an error message when trying to push a non-existant castle' do
|
||||
expect(homesick).to receive('say_status').once
|
||||
.with(:error,
|
||||
/Could not push castle_repo, expected .* exist and contain dotfiles/,
|
||||
:red)
|
||||
.with(:error, /Could not push castle_repo, expected .* exist and contain dotfiles/, :red)
|
||||
expect { homesick.push 'castle_repo' }.to raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
@@ -553,7 +613,6 @@ describe Homesick::CLI do
|
||||
# Note that this is a test for the subdir_file related feature of track,
|
||||
# not for the subdir_file method itself.
|
||||
describe 'subdir_file' do
|
||||
|
||||
it 'adds the nested files parent to the subdir_file' do
|
||||
castle = given_castle('castle_repo')
|
||||
|
||||
@@ -628,9 +687,7 @@ describe Homesick::CLI do
|
||||
|
||||
it 'returns an error message when the given castle does not exist' do
|
||||
expect(homesick).to receive('say_status').once
|
||||
.with(:error,
|
||||
/Could not cd castle_repo, expected .* exist and contain dotfiles/,
|
||||
:red)
|
||||
.with(:error, /Could not cd castle_repo, expected .* exist and contain dotfiles/, :red)
|
||||
expect { homesick.cd 'castle_repo' }.to raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
@@ -643,7 +700,7 @@ describe Homesick::CLI do
|
||||
allow(ENV).to receive(:[]).with('EDITOR').and_return('vim')
|
||||
given_castle 'castle_repo'
|
||||
expect(homesick).to receive('inside').once.with(kind_of(Pathname)).and_yield
|
||||
expect(homesick).to receive('system').once.with('vim')
|
||||
expect(homesick).to receive('system').once.with('vim .')
|
||||
Capture.stdout { homesick.open 'castle_repo' }
|
||||
end
|
||||
|
||||
@@ -651,9 +708,7 @@ describe Homesick::CLI do
|
||||
# Set the default editor to make sure it fails.
|
||||
allow(ENV).to receive(:[]).with('EDITOR').and_return(nil)
|
||||
expect(homesick).to receive('say_status').once
|
||||
.with(:error,
|
||||
'The $EDITOR environment variable must be set to use this command',
|
||||
:red)
|
||||
.with(:error, 'The $EDITOR environment variable must be set to use this command', :red)
|
||||
expect { homesick.open 'castle_repo' }.to raise_error(SystemExit)
|
||||
end
|
||||
|
||||
@@ -661,9 +716,7 @@ describe Homesick::CLI do
|
||||
# Set a default just in case none is set
|
||||
allow(ENV).to receive(:[]).with('EDITOR').and_return('vim')
|
||||
allow(homesick).to receive('say_status').once
|
||||
.with(:error,
|
||||
/Could not open castle_repo, expected .* exist and contain dotfiles/,
|
||||
:red)
|
||||
.with(:error, /Could not open castle_repo, expected .* exist and contain dotfiles/, :red)
|
||||
expect { homesick.open 'castle_repo' }.to raise_error(SystemExit)
|
||||
end
|
||||
end
|
||||
@@ -671,7 +724,7 @@ describe Homesick::CLI do
|
||||
describe 'version' do
|
||||
it 'prints the current version of homesick' do
|
||||
text = Capture.stdout { homesick.version }
|
||||
expect(text.chomp).to match(/\d+\.\d+\.\d+/)
|
||||
expect(text.chomp).to match(/#{Regexp.escape(Homesick::Version::STRING)}/)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -682,9 +735,7 @@ describe Homesick::CLI do
|
||||
it 'executes a single command with no arguments inside a given castle' do
|
||||
allow(homesick).to receive('inside').once.with(kind_of(Pathname)).and_yield
|
||||
allow(homesick).to receive('say_status').once
|
||||
.with(be_a(String),
|
||||
be_a(String),
|
||||
:green)
|
||||
.with(be_a(String), be_a(String), :green)
|
||||
allow(homesick).to receive('system').once.with('ls')
|
||||
Capture.stdout { homesick.exec 'castle_repo', 'ls' }
|
||||
end
|
||||
@@ -692,18 +743,14 @@ describe Homesick::CLI do
|
||||
it 'executes a single command with arguments inside a given castle' do
|
||||
allow(homesick).to receive('inside').once.with(kind_of(Pathname)).and_yield
|
||||
allow(homesick).to receive('say_status').once
|
||||
.with(be_a(String),
|
||||
be_a(String),
|
||||
:green)
|
||||
.with(be_a(String), be_a(String), :green)
|
||||
allow(homesick).to receive('system').once.with('ls -la')
|
||||
Capture.stdout { homesick.exec 'castle_repo', 'ls', '-la' }
|
||||
end
|
||||
|
||||
it 'raises an error when the method is called without a command' do
|
||||
allow(homesick).to receive('say_status').once
|
||||
.with(:error,
|
||||
be_a(String),
|
||||
:red)
|
||||
.with(:error, be_a(String), :red)
|
||||
allow(homesick).to receive('exit').once.with(1)
|
||||
Capture.stdout { homesick.exec 'castle_repo' }
|
||||
end
|
||||
@@ -711,9 +758,7 @@ describe Homesick::CLI do
|
||||
context 'pretend' do
|
||||
it 'does not execute a command when the pretend option is passed' do
|
||||
allow(homesick).to receive('say_status').once
|
||||
.with(be_a(String),
|
||||
match(/.*Would execute.*/),
|
||||
:green)
|
||||
.with(be_a(String), match(/.*Would execute.*/), :green)
|
||||
expect(homesick).to receive('system').never
|
||||
Capture.stdout { homesick.invoke 'exec', %w(castle_repo ls -la), pretend: true }
|
||||
end
|
||||
@@ -738,9 +783,7 @@ describe Homesick::CLI do
|
||||
it 'executes a command without arguments inside the root of each cloned castle' do
|
||||
allow(homesick).to receive('inside_each_castle').exactly(:twice).and_yield('castle_repo').and_yield('another_castle_repo')
|
||||
allow(homesick).to receive('say_status').at_least(:once)
|
||||
.with(be_a(String),
|
||||
be_a(String),
|
||||
:green)
|
||||
.with(be_a(String), be_a(String), :green)
|
||||
allow(homesick).to receive('system').at_least(:once).with('ls')
|
||||
Capture.stdout { homesick.exec_all 'ls' }
|
||||
end
|
||||
@@ -748,18 +791,14 @@ describe Homesick::CLI do
|
||||
it 'executes a command with arguments inside the root of each cloned castle' do
|
||||
allow(homesick).to receive('inside_each_castle').exactly(:twice).and_yield('castle_repo').and_yield('another_castle_repo')
|
||||
allow(homesick).to receive('say_status').at_least(:once)
|
||||
.with(be_a(String),
|
||||
be_a(String),
|
||||
:green)
|
||||
.with(be_a(String), be_a(String), :green)
|
||||
allow(homesick).to receive('system').at_least(:once).with('ls -la')
|
||||
Capture.stdout { homesick.exec_all 'ls', '-la' }
|
||||
end
|
||||
|
||||
it 'raises an error when the method is called without a command' do
|
||||
allow(homesick).to receive('say_status').once
|
||||
.with(:error,
|
||||
be_a(String),
|
||||
:red)
|
||||
.with(:error, be_a(String), :red)
|
||||
allow(homesick).to receive('exit').once.with(1)
|
||||
Capture.stdout { homesick.exec_all }
|
||||
end
|
||||
@@ -767,9 +806,7 @@ describe Homesick::CLI do
|
||||
context 'pretend' do
|
||||
it 'does not execute a command when the pretend option is passed' do
|
||||
allow(homesick).to receive('say_status').at_least(:once)
|
||||
.with(be_a(String),
|
||||
match(/.*Would execute.*/),
|
||||
:green)
|
||||
.with(be_a(String), match(/.*Would execute.*/), :green)
|
||||
expect(homesick).to receive('system').never
|
||||
Capture.stdout { homesick.invoke 'exec_all', %w(ls -la), pretend: true }
|
||||
end
|
||||
|
||||
@@ -5,7 +5,6 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
||||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
||||
require 'homesick'
|
||||
require 'rspec'
|
||||
require 'rspec/autorun'
|
||||
require 'test_construct'
|
||||
require 'tempfile'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user