hangover 0.0.5 → 0.0.6
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.
- data/bin/hangover +23 -3
- data/lib/hangover/repository.rb +17 -14
- data/lib/hangover/version.rb +1 -1
- data/lib/hangover.rb +25 -17
- metadata +2 -2
data/bin/hangover
CHANGED
@@ -1,11 +1,31 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'fileutils'
|
3
|
-
require
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
command = ARGV.shift
|
6
|
+
ARGV.unshift('-h') if command == '-h'
|
7
|
+
options = {}
|
4
8
|
|
5
|
-
command
|
9
|
+
if command == 'git'
|
10
|
+
options[:args] = ARGV.join(' ')
|
11
|
+
else
|
12
|
+
OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: hangover <command> [options]"
|
14
|
+
opts.on("-d", "--debug", "Generate debug output on $stderr") do |d|
|
15
|
+
$HANGOVER_DEBUG = true
|
16
|
+
end
|
17
|
+
opts.on("-h", "--help", "Display this help screen") do
|
18
|
+
puts opts
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
end.parse!
|
22
|
+
end
|
23
|
+
|
24
|
+
# require after options have been parsed to respect $HANGOVER_DEBUG
|
25
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/hangover')
|
6
26
|
|
7
27
|
begin
|
8
|
-
Hangover.new(`pwd`.chomp).__send__(command)
|
28
|
+
Hangover.new(`pwd`.chomp).__send__(command, options)
|
9
29
|
#rescue => e
|
10
30
|
# $stderr.puts "ERROR: #{e.message}"
|
11
31
|
# exit(1)
|
data/lib/hangover/repository.rb
CHANGED
@@ -24,17 +24,19 @@ class Repository
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def exists!
|
27
|
-
|
27
|
+
if File.directory?(@repository)
|
28
|
+
Hangover.logger.warn "Repository already exists at #{@repository}"
|
29
|
+
return
|
30
|
+
end
|
28
31
|
|
29
|
-
|
30
|
-
p "Initializing new hangover repo at #{@repository}"
|
32
|
+
Hangover.logger.info "Initializing new hangover repo at #{@repository}"
|
31
33
|
init
|
32
34
|
File.open("#{@repository}/info/exclude", "w") do |f|
|
33
35
|
f.puts NAME
|
34
36
|
f.puts ".git"
|
35
37
|
end
|
36
|
-
|
37
|
-
|
38
|
+
add_all
|
39
|
+
commit_all("Initial commit")
|
38
40
|
end
|
39
41
|
|
40
42
|
def gitk
|
@@ -42,30 +44,31 @@ class Repository
|
|
42
44
|
end
|
43
45
|
|
44
46
|
def init
|
45
|
-
|
47
|
+
git 'init'
|
46
48
|
end
|
47
49
|
|
48
|
-
def
|
49
|
-
|
50
|
+
def add_all
|
51
|
+
git 'add .'
|
50
52
|
end
|
51
53
|
|
52
54
|
def commit(message, args = '')
|
53
|
-
|
55
|
+
git "commit #{args} -m \"#{message}\""
|
54
56
|
end
|
55
57
|
|
56
|
-
def
|
58
|
+
def commit_all(message)
|
57
59
|
commit(message, '-a')
|
58
60
|
end
|
59
61
|
|
60
62
|
def diff
|
61
|
-
|
63
|
+
git 'diff --unified=0'
|
62
64
|
end
|
63
65
|
|
64
66
|
def clean
|
65
|
-
|
67
|
+
git 'clean'
|
66
68
|
end
|
67
69
|
|
68
|
-
def git(
|
69
|
-
|
70
|
+
def git(args)
|
71
|
+
Hangover.logger.debug { "git #{args}" }
|
72
|
+
`git #{args}`
|
70
73
|
end
|
71
74
|
end
|
data/lib/hangover/version.rb
CHANGED
data/lib/hangover.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rb-fsevent'
|
2
2
|
require 'active_support/core_ext'
|
3
|
+
require 'logger'
|
3
4
|
|
4
5
|
$:.push(File.expand_path(File.dirname(__FILE__)))
|
5
6
|
|
@@ -10,13 +11,17 @@ require 'hangover/watch_dir'
|
|
10
11
|
|
11
12
|
class Hangover
|
12
13
|
|
14
|
+
cattr_accessor :logger
|
15
|
+
@@logger = Logger.new($stderr)
|
16
|
+
@@logger.level = $HANGOVER_DEBUG ? Logger::DEBUG : Logger::INFO
|
17
|
+
|
13
18
|
def initialize(base_dir)
|
14
19
|
@base_dir = expand_dir(base_dir)
|
15
20
|
end
|
16
21
|
|
17
|
-
def start
|
22
|
+
def start(options)
|
18
23
|
exit_if_running!
|
19
|
-
|
24
|
+
logger.info "Hangover starting..."
|
20
25
|
daemonize!
|
21
26
|
|
22
27
|
WatchDir.new(@base_dir).on_change do |dir|
|
@@ -29,41 +34,40 @@ class Hangover
|
|
29
34
|
tokenizer = DiffTokenizer.new(diff)
|
30
35
|
|
31
36
|
message = CommitMessageBuilder.new(tokenizer.top_adds, tokenizer.top_subs).message
|
32
|
-
repository.
|
33
|
-
repository.
|
37
|
+
repository.add_all
|
38
|
+
repository.commit_all(message)
|
34
39
|
end
|
35
40
|
end
|
36
41
|
|
37
|
-
def stop
|
42
|
+
def stop(options)
|
38
43
|
if running?
|
39
44
|
Process.kill(15, pid)
|
40
|
-
|
45
|
+
logger.info "Hangover stopped."
|
41
46
|
else
|
42
|
-
|
47
|
+
logger.info "Hangover not running."
|
43
48
|
end
|
44
49
|
ensure
|
45
50
|
remove_pid if File.exist?(pid_file)
|
46
51
|
end
|
47
52
|
|
48
|
-
def create
|
53
|
+
def create(options)
|
49
54
|
Repository.new(@base_dir).exists!
|
50
55
|
end
|
51
56
|
|
52
|
-
def gitk
|
57
|
+
def gitk(options)
|
53
58
|
Repository.new(@base_dir).gitk
|
54
59
|
end
|
55
60
|
|
56
|
-
def status
|
61
|
+
def status(options)
|
57
62
|
if running?
|
58
|
-
|
63
|
+
logger.info "Hangover is running and watching #{@base_dir}"
|
59
64
|
else
|
60
|
-
|
65
|
+
logger.info "Hangover NOT running."
|
61
66
|
end
|
62
67
|
end
|
63
68
|
|
64
|
-
def git(
|
65
|
-
|
66
|
-
$stderr.puts Repository.new(@base_dir).git(args_string)
|
69
|
+
def git(options)
|
70
|
+
logger.info Repository.new(@base_dir).git(options[:args])
|
67
71
|
end
|
68
72
|
|
69
73
|
private
|
@@ -96,7 +100,7 @@ class Hangover
|
|
96
100
|
Process.kill(0, pid) == 1 if pid
|
97
101
|
rescue Errno::ESRCH
|
98
102
|
if File.exist?(pid_file)
|
99
|
-
|
103
|
+
logger.info "Removing stale pid file."
|
100
104
|
remove_pid
|
101
105
|
end
|
102
106
|
false
|
@@ -105,7 +109,7 @@ class Hangover
|
|
105
109
|
def exit_if_running!
|
106
110
|
return unless running?
|
107
111
|
|
108
|
-
|
112
|
+
logger.info "Hangover already running."
|
109
113
|
exit(0)
|
110
114
|
end
|
111
115
|
|
@@ -113,4 +117,8 @@ class Hangover
|
|
113
117
|
Process.daemon(true, true)
|
114
118
|
write_pid
|
115
119
|
end
|
120
|
+
|
121
|
+
def logger
|
122
|
+
self.class.logger
|
123
|
+
end
|
116
124
|
end
|