dit 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dit.rb +51 -33
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3c4c89fb99119f2cfd0a0d85295b43d502f3221
|
4
|
+
data.tar.gz: 129081c7feed5a0c291afd6c3a1c2b61343441fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1cd1d7ee772cf636c6e90f1e69f1f6e4d304f4f0ba8f96ba8ed345a5570bd7960e6abb8ce91008e8c9fc83634fc04fb1782d85b3221d0e167d51889a727b5db
|
7
|
+
data.tar.gz: 334f0e4709b9e9a97f43932d6d1d3259311d125e2e59be1750da8cd3fff53faaf96cc1d85bbcf90f2aaef1a5aee2c9ba16229abd09a08b20dde6ba77a034b9d8
|
data/lib/dit.rb
CHANGED
@@ -4,41 +4,52 @@ require 'os'
|
|
4
4
|
require 'json'
|
5
5
|
require 'fileutils'
|
6
6
|
|
7
|
+
# This is the class where all the dit work is done.
|
8
|
+
# The thor class is basically a very thin layer on top of this that just
|
9
|
+
# calls its methods directly.
|
10
|
+
# This is because the hooks are not running through the Thor object, but also
|
11
|
+
# referencing these methods.
|
7
12
|
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.
|
11
13
|
def self.init
|
12
|
-
|
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.'
|
15
|
-
return
|
16
|
-
end
|
14
|
+
exit_if_windows
|
17
15
|
|
18
16
|
if Dir.exist?('.git')
|
19
|
-
|
20
|
-
'populate your ~ directory with symlinks.'
|
21
|
-
puts 'Please confirm this by typing y, or anything else to cancel.'
|
22
|
-
response = STDIN.gets.chomp.upcase
|
23
|
-
return unless (response == 'Y')
|
24
|
-
symlink_all
|
17
|
+
symlink_all if prompt_for_symlink_all
|
25
18
|
else
|
26
19
|
Git.init(Dir.getwd)
|
27
20
|
puts "Initialized empty Git repository in #{File.join(Dir.getwd, '.git')}"
|
28
21
|
end
|
22
|
+
|
29
23
|
hook
|
24
|
+
|
30
25
|
puts 'Dit was successfully hooked into .git/hooks.'
|
31
26
|
end
|
32
27
|
|
28
|
+
def self.exit_if_windows
|
29
|
+
if OS.windows?
|
30
|
+
puts 'This is a windows system, and dit does not support windows.'
|
31
|
+
puts 'See vulpino/dit issue #1 if you have a potential solution.'
|
32
|
+
exit 1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.prompt_for_symlink_all
|
37
|
+
puts 'Dit has detected an existing git repo, and will initialize it to ' +
|
38
|
+
'populate your ~ directory with symlinks.'
|
39
|
+
puts 'Please confirm this by typing y, or anything else to cancel.'
|
40
|
+
response = STDIN.gets.chomp.upcase
|
41
|
+
response == 'Y'
|
42
|
+
end
|
43
|
+
|
33
44
|
def self.hook
|
34
45
|
Dir.chdir(File.join('.git', 'hooks')) do
|
35
46
|
# The following check for the existence of post-commit or post-merge hooks
|
36
47
|
# and will not interfere with them if they exist and do not use bash.
|
37
|
-
append_to_post_commit, cannot_post_commit =
|
38
|
-
append_to_post_merge, cannot_post_merge =
|
48
|
+
append_to_post_commit, cannot_post_commit = detect_hook 'post-commit'
|
49
|
+
append_to_post_merge, cannot_post_merge = detect_hook 'post-merge'
|
39
50
|
|
40
|
-
|
41
|
-
|
51
|
+
write_hook('post-commit', append_to_post_commit) unless cannot_post_commit
|
52
|
+
write_hook('post-merge', append_to_post_merge) unless cannot_post_merge
|
42
53
|
|
43
54
|
make_dit
|
44
55
|
make_ruby_enforcer
|
@@ -76,24 +87,22 @@ class Dit
|
|
76
87
|
puts "Failed to symlink #{a} to #{b}"
|
77
88
|
end
|
78
89
|
|
79
|
-
def self.
|
80
|
-
|
90
|
+
def self.detect_hook(hook)
|
91
|
+
return [false, false] unless File.exist?(hook)
|
81
92
|
|
82
93
|
cannot_hook, append_to_hook = false
|
83
94
|
|
84
|
-
if
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
cannot_hook = true
|
96
|
-
end
|
95
|
+
if `cat #{hook}`.include?('./.git/hooks/dit')
|
96
|
+
puts 'Dit hook already installed.'
|
97
|
+
cannot_hook = true
|
98
|
+
elsif `cat #{hook}`.include?('#!/usr/bin/env bash')
|
99
|
+
puts "You have #{hook} hooks already that use bash, so we'll " +
|
100
|
+
'append ourselves to the file.'
|
101
|
+
append_to_hook = true
|
102
|
+
else
|
103
|
+
puts "You have #{hook} hooks that use some foreign language, " +
|
104
|
+
"so we won't interfere, but we can't hook in there."
|
105
|
+
cannot_hook = true
|
97
106
|
end
|
98
107
|
|
99
108
|
[append_to_hook, cannot_hook]
|
@@ -143,6 +152,10 @@ class Dit
|
|
143
152
|
end
|
144
153
|
end
|
145
154
|
end
|
155
|
+
|
156
|
+
def self.version
|
157
|
+
'0.2.3'
|
158
|
+
end
|
146
159
|
end
|
147
160
|
|
148
161
|
class DitCMD < Thor
|
@@ -155,4 +168,9 @@ class DitCMD < Thor
|
|
155
168
|
def rehash
|
156
169
|
Dit.symlink_all
|
157
170
|
end
|
171
|
+
|
172
|
+
desc 'version', 'Print the dit version.'
|
173
|
+
def version
|
174
|
+
puts "Dit #{Dit.version} on ruby #{RUBY_VERSION}"
|
175
|
+
end
|
158
176
|
end
|