dit 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dit.rb +51 -33
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06fd6b92b3c391f88bca25aa648a6878f687f628
4
- data.tar.gz: f673fc052775a29a66c83e5901bb60b3861c5995
3
+ metadata.gz: b3c4c89fb99119f2cfd0a0d85295b43d502f3221
4
+ data.tar.gz: 129081c7feed5a0c291afd6c3a1c2b61343441fe
5
5
  SHA512:
6
- metadata.gz: 30c40ac1342985a2008b4e0f573b43f82226160142188036482d79fab5abc77bdddae06c57dd57f16c4376b621a0b0d4f98c2d16ac9d38ca0bdb9b1498c47b14
7
- data.tar.gz: d159ee212b017368be94f3dd84b14ad907f6ffda3b0c24f8142e4d8c4a3a1165da4fa405c53cc0cb0f873caf90eb7924c43d4b4597f934f1bd8298d4d241c97a
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
- if OS.windows?
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
- 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.'
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 = hook 'post-commit'
38
- append_to_post_merge, cannot_post_merge = hook '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
- 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
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.detect_existing_hook(hook)
80
- hook_exists = File.exist?(hook)
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 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
92
- else
93
- puts "You have #{hook} hooks that use some foreign language, " +
94
- "so we won't interfere, but we can't hook in there."
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
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.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Fahringer