dit 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dit.rb +82 -99
- metadata +1 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06fd6b92b3c391f88bca25aa648a6878f687f628
|
4
|
+
data.tar.gz: f673fc052775a29a66c83e5901bb60b3861c5995
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30c40ac1342985a2008b4e0f573b43f82226160142188036482d79fab5abc77bdddae06c57dd57f16c4376b621a0b0d4f98c2d16ac9d38ca0bdb9b1498c47b14
|
7
|
+
data.tar.gz: d159ee212b017368be94f3dd84b14ad907f6ffda3b0c24f8142e4d8c4a3a1165da4fa405c53cc0cb0f873caf90eb7924c43d4b4597f934f1bd8298d4d241c97a
|
data/lib/dit.rb
CHANGED
@@ -5,82 +5,43 @@ require 'json'
|
|
5
5
|
require 'fileutils'
|
6
6
|
|
7
7
|
class Dit
|
8
|
+
# This is the class where all the dit work is done.
|
9
|
+
# The thor class is basically a very thin layer on top of this that just
|
10
|
+
# calls its methods directly.
|
8
11
|
def self.init
|
9
12
|
if OS.windows?
|
10
|
-
puts
|
11
|
-
puts
|
13
|
+
puts 'This is a windows system, and dit does not support windows.'
|
14
|
+
puts 'See vulpino/dit issue #1 if you have a potential solution.'
|
12
15
|
return
|
13
16
|
end
|
14
17
|
|
15
|
-
if Dir.exist?(
|
16
|
-
puts
|
17
|
-
|
18
|
-
puts
|
18
|
+
if Dir.exist?('.git')
|
19
|
+
puts 'Dit has detected an existing git repo, and will initialize it to ' +
|
20
|
+
'populate your ~ directory with symlinks.'
|
21
|
+
puts 'Please confirm this by typing y, or anything else to cancel.'
|
19
22
|
response = STDIN.gets.chomp.upcase
|
20
|
-
return unless (response
|
23
|
+
return unless (response == 'Y')
|
21
24
|
symlink_all
|
22
25
|
else
|
23
26
|
Git.init(Dir.getwd)
|
24
|
-
puts "Initialized empty Git repository in #{File.join(Dir.getwd,
|
27
|
+
puts "Initialized empty Git repository in #{File.join(Dir.getwd, '.git')}"
|
25
28
|
end
|
26
29
|
hook
|
27
|
-
puts
|
30
|
+
puts 'Dit was successfully hooked into .git/hooks.'
|
28
31
|
end
|
29
32
|
|
30
33
|
def self.hook
|
31
|
-
Dir.chdir(File.join(
|
34
|
+
Dir.chdir(File.join('.git', 'hooks')) do
|
32
35
|
# The following check for the existence of post-commit or post-merge hooks
|
33
36
|
# and will not interfere with them if they exist and do not use bash.
|
34
|
-
append_to_post_commit,
|
35
|
-
|
37
|
+
append_to_post_commit, cannot_post_commit = hook 'post-commit'
|
38
|
+
append_to_post_merge, cannot_post_merge = hook 'post-merge'
|
36
39
|
|
37
|
-
unless cannot_post_commit
|
38
|
-
|
39
|
-
f.write "#!/usr/bin/env bash\n" unless append_to_post_commit
|
40
|
-
f.write "( exec ./.git/hooks/dit )\n"
|
41
|
-
end
|
42
|
-
end
|
40
|
+
add_hook('post-commit', append_to_post_commit) unless cannot_post_commit
|
41
|
+
add_hook('post-merge', append_to_post_merge) unless cannot_post_merge
|
43
42
|
|
44
|
-
|
45
|
-
|
46
|
-
f.write "#!/usr/bin/env bash\n" unless append_to_post_merge
|
47
|
-
f.write "( exec ./.git/hooks/dit )\n"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
File.open("dit", "a") do |f|
|
52
|
-
f.write "#!/usr/bin/env ./.git/hooks/force-ruby\n"
|
53
|
-
f.write "require 'dit'\n"
|
54
|
-
f.write "Dit.symlink_unlinked\n"
|
55
|
-
end
|
56
|
-
|
57
|
-
# The following lines are because git hooks do this weird thing
|
58
|
-
# where they prepend /usr/bin to the path and a bunch of other stuff
|
59
|
-
# meaning git hooks will use /usr/bin/ruby instead of any ruby
|
60
|
-
# from rbenv or rvm or chruby, so we make a script forcing the hook
|
61
|
-
# to use our ruby
|
62
|
-
ruby_path = `which ruby`
|
63
|
-
if(ruby_path != "/usr/bin/ruby")
|
64
|
-
ruby_folder = File.dirname(ruby_path)
|
65
|
-
File.open("force-ruby", "a") do |f|
|
66
|
-
f.write "#!/usr/bin/env bash\n"
|
67
|
-
f.write "set -e\n"
|
68
|
-
if ENV['RBENV_ROOT']
|
69
|
-
# Use Rbenv's shims instead of directly going to ruby bin
|
70
|
-
# By the way, if anyone has particular PATHs I should use for
|
71
|
-
# RVM or chruby, please let me know!
|
72
|
-
f.write "PATH=#{File.join(ENV['RBENV_ROOT'], "shims")}:$PATH\n"
|
73
|
-
else
|
74
|
-
f.write "PATH=#{ruby_folder}:$PATH\n"
|
75
|
-
end
|
76
|
-
f.write "exec ruby \"$@\"\n"
|
77
|
-
end
|
78
|
-
else
|
79
|
-
File.open("force-ruby", "a") do |f|
|
80
|
-
f.write "#!/usr/bin/env bash\n"
|
81
|
-
f.write "exec ruby \"$@\"\n"
|
82
|
-
end
|
83
|
-
end
|
43
|
+
make_dit
|
44
|
+
make_ruby_enforcer
|
84
45
|
|
85
46
|
# Make sure they're executable
|
86
47
|
FileUtils.chmod '+x', %w(post-commit post-merge dit force-ruby)
|
@@ -105,70 +66,92 @@ class Dit
|
|
105
66
|
symlink_list `git ls-tree -r #{current_branch} --name-only`.split("\n")
|
106
67
|
end
|
107
68
|
|
108
|
-
private
|
109
|
-
|
110
69
|
def self.repo
|
111
70
|
Git.open(Dir.getwd)
|
112
71
|
end
|
113
72
|
|
114
73
|
def self.symlink(a, b)
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
puts "Failed to symlink #{a} to #{b}"
|
119
|
-
end
|
74
|
+
File.symlink(a, b)
|
75
|
+
rescue
|
76
|
+
puts "Failed to symlink #{a} to #{b}"
|
120
77
|
end
|
121
78
|
|
122
|
-
def self.
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
puts "Dit hook already installed."
|
136
|
-
cannot_post_commit = true
|
79
|
+
def self.detect_existing_hook(hook)
|
80
|
+
hook_exists = File.exist?(hook)
|
81
|
+
|
82
|
+
cannot_hook, append_to_hook = false
|
83
|
+
|
84
|
+
if hook_exists
|
85
|
+
if `cat #{hook}`.include?('./.git/hooks/dit')
|
86
|
+
puts 'Dit hook already installed.'
|
87
|
+
cannot_hook = true
|
88
|
+
elsif `cat #{hook}`.include?('#!/usr/bin/env bash')
|
89
|
+
puts "You have #{hook} hooks already that use bash, so we'll " +
|
90
|
+
'append ourselves to the file.'
|
91
|
+
append_to_hook = true
|
137
92
|
else
|
138
|
-
puts "You have
|
93
|
+
puts "You have #{hook} hooks that use some foreign language, " +
|
139
94
|
"so we won't interfere, but we can't hook in there."
|
140
|
-
|
95
|
+
cannot_hook = true
|
141
96
|
end
|
142
97
|
end
|
143
98
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
cannot_post_commit = true
|
152
|
-
else
|
153
|
-
puts "You have post-merge hooks that use some not-bash language, " +
|
154
|
-
"so we won't interfere, but we can't hook in there."
|
155
|
-
cannot_post_merge = true
|
156
|
-
end
|
99
|
+
[append_to_hook, cannot_hook]
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.write_hook(hook_file, do_append)
|
103
|
+
File.open(hook_file, 'a') do |f|
|
104
|
+
f.write "#!/usr/bin/env bash\n" unless do_append
|
105
|
+
f.write "( exec ./.git/hooks/dit )\n"
|
157
106
|
end
|
107
|
+
end
|
158
108
|
|
159
|
-
|
160
|
-
|
109
|
+
def self.make_dit
|
110
|
+
File.open('dit', 'a') do |f|
|
111
|
+
f.write "#!/usr/bin/env ./.git/hooks/force-ruby\n"
|
112
|
+
f.write "require 'dit'\n"
|
113
|
+
f.write "Dit.symlink_unlinked\n"
|
114
|
+
end
|
161
115
|
end
|
162
116
|
|
117
|
+
def self.make_ruby_enforcer
|
118
|
+
# The following lines are because git hooks do this weird thing
|
119
|
+
# where they prepend /usr/bin to the path and a bunch of other stuff
|
120
|
+
# meaning git hooks will use /usr/bin/ruby instead of any ruby
|
121
|
+
# from rbenv or rvm or chruby, so we make a script forcing the hook
|
122
|
+
# to use our ruby
|
123
|
+
ruby_path = `which ruby`
|
124
|
+
if ruby_path != '/usr/bin/ruby'
|
125
|
+
ruby_folder = File.dirname(ruby_path)
|
126
|
+
File.open('force-ruby', 'a') do |f|
|
127
|
+
f.write "#!/usr/bin/env bash\n"
|
128
|
+
f.write "set -e\n"
|
129
|
+
if ENV['RBENV_ROOT']
|
130
|
+
# Use Rbenv's shims instead of directly going to ruby bin
|
131
|
+
# By the way, if anyone has particular PATHs I should use for
|
132
|
+
# RVM or chruby, please let me know!
|
133
|
+
f.write "PATH=#{File.join(ENV['RBENV_ROOT'], 'shims')}:$PATH\n"
|
134
|
+
else
|
135
|
+
f.write "PATH=#{ruby_folder}:$PATH\n"
|
136
|
+
end
|
137
|
+
f.write "exec ruby \"$@\"\n"
|
138
|
+
end
|
139
|
+
else
|
140
|
+
File.open('force-ruby', 'a') do |f|
|
141
|
+
f.write "#!/usr/bin/env bash\n"
|
142
|
+
f.write "exec ruby \"$@\"\n"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
163
146
|
end
|
164
147
|
|
165
148
|
class DitCMD < Thor
|
166
|
-
desc
|
149
|
+
desc 'init', 'Initialize the current directory as a dit directory.'
|
167
150
|
def init
|
168
151
|
Dit.init
|
169
152
|
end
|
170
153
|
|
171
|
-
desc
|
154
|
+
desc 'rehash', "Manually symlink everything in case a git hook didn't run."
|
172
155
|
def rehash
|
173
156
|
Dit.symlink_all
|
174
157
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Fahringer
|
@@ -93,4 +93,3 @@ signing_key:
|
|
93
93
|
specification_version: 4
|
94
94
|
summary: Dit is a dotfiles manager that thinks it's git.
|
95
95
|
test_files: []
|
96
|
-
has_rdoc:
|