dit 0.1.1 → 0.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 +96 -103
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40c3229cc364f6d858c3ff061c564eb1009fa661
|
4
|
+
data.tar.gz: d60799dfbfe44a94c0d478b8e58b09d7e653df00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 755aae9e97a7139012a64e04f5efe9a44922af945f4ef322a56a94b0da3a21c39864a97333f315e221f72b515489e82f3b70b888cccd0aa87077df0ba913f65f
|
7
|
+
data.tar.gz: b0bc69bde3916ff81847a53830a8e340c722c67cd8cf7c5c78250c4001419552587a46989a0816c9bfceb49006e5ec228007019e0c94bc08ed5ba160c270dd1f
|
data/lib/dit.rb
CHANGED
@@ -6,59 +6,53 @@ require 'fileutils'
|
|
6
6
|
|
7
7
|
class Dit
|
8
8
|
def self.init
|
9
|
-
if
|
10
|
-
puts "This is
|
11
|
-
|
12
|
-
hook
|
9
|
+
if OS.windows?
|
10
|
+
puts "This is a windows system, and dit does not support windows."
|
11
|
+
puts "See vulpino/dit issue #1 if you have a potential solution."
|
13
12
|
return
|
14
|
-
elsif(Dir.exist?(".git"))
|
15
|
-
repo = Git.open(Dir.getwd)
|
16
|
-
else
|
17
|
-
repo = Git.init(Dir.getwd)
|
18
|
-
puts "Initialized empty Git repository in #{File.join(Dir.getwd, ".git")}"
|
19
13
|
end
|
20
14
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
# Write our changes to a JSON file in the dit dir
|
33
|
-
File.open(File.join(".dit", "settings.json"), "a") do |f|
|
34
|
-
f.write settings.to_json if settings
|
15
|
+
if Dir.exist?(".git")
|
16
|
+
puts "Dit has detected an existing git repo, and will initialize it to " +
|
17
|
+
"populate your ~ directory with symlinks."
|
18
|
+
puts "Please confirm this by typing y, or anything else to cancel."
|
19
|
+
return unless gets.chomp! === 'y'
|
20
|
+
symlink_all
|
21
|
+
else
|
22
|
+
Git.init(Dir.getwd)
|
23
|
+
puts "Initialized empty Git repository in #{File.join(Dir.getwd, ".git")}"
|
35
24
|
end
|
36
|
-
|
37
|
-
repo.add(".dit/settings.json")
|
38
|
-
repo.add(".gitignore")
|
39
|
-
repo.commit("Dit inital commit")
|
40
|
-
|
41
|
-
clone_os_dotfiles
|
42
25
|
hook
|
43
|
-
|
44
|
-
puts "Initialized empty Dit repository in #{File.join(Dir.getwd, ".dit")})"
|
26
|
+
puts "Dit was successfully hooked into .git/hooks."
|
45
27
|
end
|
46
28
|
|
47
29
|
def self.hook
|
48
|
-
return unless Dir.exist?(".dit")
|
49
30
|
Dir.chdir(File.join(".git", "hooks")) do
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
31
|
+
# The following check for the existence of post-commit or post-merge hooks
|
32
|
+
# and will not interfere with them if they exist and do not use bash.
|
33
|
+
append_to_post_commit, append_to_post_merge, cannot_post_commit,
|
34
|
+
cannot_post_merge = detect_existing_hooks
|
35
|
+
|
36
|
+
unless cannot_post_commit
|
37
|
+
File.open("post-commit", "a") do |f|
|
38
|
+
f.write "#!/usr/bin/env bash\n" unless append_to_post_commit
|
39
|
+
f.write "( exec ./.git/hooks/dit )\n"
|
40
|
+
end
|
56
41
|
end
|
57
|
-
|
42
|
+
|
43
|
+
unless cannot_post_merge
|
44
|
+
File.open("post-merge", "a") do |f|
|
45
|
+
f.write "#!/usr/bin/env bash\n" unless append_to_post_merge
|
46
|
+
f.write "( exec ./.git/hooks/dit )\n"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
File.open("dit", "a") do |f|
|
58
51
|
f.write "#!/usr/bin/env ./.git/hooks/force-ruby\n"
|
59
52
|
f.write "require 'dit'\n"
|
60
53
|
f.write "Dit.symlink_unlinked\n"
|
61
54
|
end
|
55
|
+
|
62
56
|
# The following lines are because git hooks do this weird thing
|
63
57
|
# where they prepend /usr/bin to the path and a bunch of other stuff
|
64
58
|
# meaning git hooks will use /usr/bin/ruby instead of any ruby
|
@@ -67,11 +61,11 @@ class Dit
|
|
67
61
|
ruby_path = `which ruby`
|
68
62
|
if(ruby_path != "/usr/bin/ruby")
|
69
63
|
ruby_folder = File.dirname(ruby_path)
|
70
|
-
File.open(
|
64
|
+
File.open("force-ruby", "a") do |f|
|
71
65
|
f.write "#!/usr/bin/env bash\n"
|
72
66
|
f.write "set -e\n"
|
73
67
|
if ENV['RBENV_ROOT']
|
74
|
-
# Use Rbenv's shims
|
68
|
+
# Use Rbenv's shims instead of directly going to ruby bin
|
75
69
|
# By the way, if anyone has particular PATHs I should use for
|
76
70
|
# RVM or chruby, please let me know!
|
77
71
|
f.write "PATH=#{File.join(ENV['RBENV_ROOT'], "shims")}:$PATH\n"
|
@@ -80,89 +74,83 @@ class Dit
|
|
80
74
|
end
|
81
75
|
f.write "exec ruby \"$@\"\n"
|
82
76
|
end
|
77
|
+
else
|
78
|
+
File.open("force-ruby", "a") do |f|
|
79
|
+
f.write "#!/usr/bin/env bash\n"
|
80
|
+
f.write "exec ruby \"$@\"\n"
|
81
|
+
end
|
83
82
|
end
|
84
|
-
|
85
|
-
FileUtils.chmod '+x', %w(post-commit post-merge force-ruby)
|
83
|
+
# Make sure they're executable
|
84
|
+
FileUtils.chmod '+x', %w(post-commit post-merge dit force-ruby)
|
86
85
|
end
|
87
86
|
end
|
88
87
|
|
89
|
-
def self.
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
os_dotfiles.branch("master").checkout
|
88
|
+
def self.symlink_list(list)
|
89
|
+
list.each do |f|
|
90
|
+
wd_f = File.absolute_path f
|
91
|
+
home_f = File.absolute_path(f).gsub(Dir.getwd, Dir.home)
|
92
|
+
symlink wd_f, home_f
|
95
93
|
end
|
96
94
|
end
|
97
95
|
|
96
|
+
def self.symlink_unlinked
|
97
|
+
symlink_list `git show --pretty="format:" --name-only HEAD`.split("\n")
|
98
|
+
end
|
99
|
+
|
98
100
|
def self.symlink_all
|
99
|
-
|
100
|
-
|
101
|
-
if File.directory?(d)
|
102
|
-
Dir.mkdir(File.join(Dir.home, d.split['os_dotfiles'][1]))
|
103
|
-
Dir.entries(d).each do |f|
|
104
|
-
next if (f === '.' || f === '..')
|
105
|
-
abs_f = File.absolute_path(f)
|
106
|
-
rel_f = File.join(Dir.home, abs_f.split("os_dotfiles")[1])
|
107
|
-
File.symlink(abs_f, rel_f) unless File.exists?(rel_f)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
101
|
+
current_branch = `git rev-parse --abbrev-ref HEAD`
|
102
|
+
symlink_list `git ls-tree -r #{current_branch} --name-only`.split("\n")
|
112
103
|
end
|
113
104
|
|
114
|
-
|
115
|
-
|
105
|
+
private
|
106
|
+
|
107
|
+
def self.repo
|
108
|
+
Git.open(Dir.getwd)
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.symlink(a, b)
|
116
112
|
begin
|
117
|
-
|
118
|
-
File.join(Dir.getwd, ".dit", "local_settings.json"), "r").read.close
|
113
|
+
File.symlink(a, b)
|
119
114
|
rescue
|
120
|
-
|
121
|
-
symlinked: []
|
122
|
-
}
|
115
|
+
puts "Failed to symlink #{a} to #{b}"
|
123
116
|
end
|
117
|
+
end
|
124
118
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
119
|
+
def self.detect_existing_hooks
|
120
|
+
post_commit_hook_exists = File.exist?("post-commit")
|
121
|
+
post_merge_hook_exists = File.exist?("post-merge")
|
122
|
+
|
123
|
+
cannot_post_commit, append_to_post_commit = false
|
124
|
+
cannot_post_merge, append_to_post_merge = false
|
125
|
+
|
126
|
+
if post_commit_hook_exists
|
127
|
+
if `cat post-commit`.include?("#!/usr/bin/env bash")
|
128
|
+
puts "You have post-commit hooks already that use bash, so we'll " +
|
129
|
+
"append ourselves to the file."
|
130
|
+
append_to_post_commit = true
|
131
|
+
else
|
132
|
+
puts "You have post-commit hooks that use some foreign language, " +
|
133
|
+
"so we won't interfere, but we can't hook in there."
|
134
|
+
cannot_post_commit = true
|
139
135
|
end
|
140
136
|
end
|
141
137
|
|
142
|
-
|
143
|
-
|
144
|
-
|
138
|
+
if post_merge_hook_exists
|
139
|
+
if `cat post-merge`.include?("#!/usr/bin/env bash")
|
140
|
+
puts "You have post-merge hooks already that use bash, so we'll " +
|
141
|
+
"append ourselve to the file."
|
142
|
+
append_to_post_merge = true
|
143
|
+
else
|
144
|
+
puts "You have post-merge hooks that use some not-bash language, " +
|
145
|
+
"so we won't interfere, but we can't hook in there."
|
146
|
+
cannot_post_merge = true
|
147
|
+
end
|
145
148
|
end
|
146
|
-
end
|
147
149
|
|
148
|
-
|
149
|
-
|
150
|
-
def self.repo
|
151
|
-
Git.open(Dir.getwd)
|
150
|
+
[append_to_post_commit, append_to_post_merge,
|
151
|
+
cannot_post_commit, cannot_post_merge]
|
152
152
|
end
|
153
153
|
|
154
|
-
def self.os_list
|
155
|
-
[
|
156
|
-
'windows',
|
157
|
-
'osx',
|
158
|
-
'arch',
|
159
|
-
'fedora',
|
160
|
-
'debian',
|
161
|
-
'ubuntu',
|
162
|
-
'slack',
|
163
|
-
'bsd'
|
164
|
-
]
|
165
|
-
end
|
166
154
|
end
|
167
155
|
|
168
156
|
class DitCMD < Thor
|
@@ -170,4 +158,9 @@ class DitCMD < Thor
|
|
170
158
|
def init
|
171
159
|
Dit.init
|
172
160
|
end
|
161
|
+
|
162
|
+
desc "rehash", "Manually symlink everything in case a git hook didn't run."
|
163
|
+
def rehash
|
164
|
+
Dit.symlink_all
|
165
|
+
end
|
173
166
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Fahringer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|