Legit-the-Git 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +21 -0
- data/bin/accuhook +14 -0
- data/legit-the-git.gemspec +28 -0
- data/lib/accuhook.rb +7 -0
- data/lib/accuhook/command.rb +34 -0
- data/lib/accuhook/command_line.rb +57 -0
- data/lib/accuhook/commit.rb +36 -0
- data/lib/accuhook/hooks/post-commit +16 -0
- data/lib/accuhook/hooks/pre-commit +10 -0
- metadata +90 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) <year> <copyright holders>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/bin/accuhook
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2011 Grayson Manley
|
4
|
+
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license
|
5
|
+
|
6
|
+
# DEVELOPMENT_DIR = "/Users/tukaiz/projects/accurev_git_hooks"
|
7
|
+
begin
|
8
|
+
require 'rubygems'
|
9
|
+
require 'accuhook'
|
10
|
+
rescue LoadError => e
|
11
|
+
require File.join(DEVELOPMENT_DIR, "lib", "accuhook")
|
12
|
+
end
|
13
|
+
|
14
|
+
AccuHook::CommandLine.execute(ARGV)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (c) 2011 Grayson Manley
|
2
|
+
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "Legit-the-Git"
|
6
|
+
s.version = "0.0.1"
|
7
|
+
|
8
|
+
s.summary = "Git accurev bridge"
|
9
|
+
s.description = "Git hooks to help keep accurev and git in sync"
|
10
|
+
s.homepage = "http://github.com/gmanley/Legit-the-Git"
|
11
|
+
s.license = "MIT"
|
12
|
+
s.authors = ["Grayson Manley"]
|
13
|
+
s.email = "gray.manley@gmail.com"
|
14
|
+
s.default_executable = "accuhook"
|
15
|
+
s.executables = ["accuhook"]
|
16
|
+
s.files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"legit-the-git.gemspec",
|
19
|
+
"bin/accuhook",
|
20
|
+
"lib/accuhook.rb",
|
21
|
+
"lib/accuhook/command.rb",
|
22
|
+
"lib/accuhook/command_line.rb",
|
23
|
+
"lib/accuhook/commit.rb",
|
24
|
+
"lib/accuhook/hooks/post-commit",
|
25
|
+
"lib/accuhook/hooks/pre-commit"
|
26
|
+
]
|
27
|
+
s.add_runtime_dependency("grit", ["~> 2.3.0"])
|
28
|
+
end
|
data/lib/accuhook.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Copyright (c) 2011 Grayson Manley
|
2
|
+
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'grit'
|
6
|
+
require File.dirname(__FILE__) + '/accuhook/command_line'
|
7
|
+
require File.dirname(__FILE__) + '/accuhook/commit'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Copyright (c) 2011 Grayson Manley
|
2
|
+
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license
|
3
|
+
|
4
|
+
module AccuHook
|
5
|
+
module Accurev
|
6
|
+
class Command
|
7
|
+
require "shellwords"
|
8
|
+
|
9
|
+
def add(file_path)
|
10
|
+
if File.directory?(file_path) # Recursively add directory (`accurev add -x -R {Dir}`)
|
11
|
+
execute("add -x -R #{file_path}")
|
12
|
+
else # Add single file (`accurev add {File}`)
|
13
|
+
execute("add #{file_path}")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def keep(file_path, message)
|
18
|
+
execute("keep -c #{message} #{file_path}")
|
19
|
+
end
|
20
|
+
|
21
|
+
def defunct(file_path, message)
|
22
|
+
execute("defunct -c #{@last_commit_message} #{diff.a_path}")
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def execute(command)
|
27
|
+
args = Shellwords.split(command)
|
28
|
+
escaped_args = args.map {|arg| Shellwords.escape(arg)}
|
29
|
+
sub_command = Shellwords.join(escaped_args)
|
30
|
+
system("accurev #{sub_command}")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Copyright (c) 2011 Grayson Manley
|
2
|
+
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
require 'ostruct'
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
module AccuHook
|
9
|
+
class CommandLine
|
10
|
+
# Parse command line options and execute
|
11
|
+
def self.execute(args)
|
12
|
+
options = parse_options(args)
|
13
|
+
|
14
|
+
case options.command
|
15
|
+
when :install
|
16
|
+
ret_val = AccuHook::Installation.new(options.path)
|
17
|
+
exit 0
|
18
|
+
when :version
|
19
|
+
puts 'Version 0.0.1'
|
20
|
+
exit 0
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def self.parse_options(args)
|
26
|
+
options = OpenStruct.new
|
27
|
+
options.command = :help
|
28
|
+
options.path = Dir.pwd
|
29
|
+
|
30
|
+
opts = OptionParser.new do |opts|
|
31
|
+
opts.banner = "Usage #{File.basename $0} [options]"
|
32
|
+
opts.on_head("-i","--install", "Install Accurev Git hook in current dir") { options.command = :install }
|
33
|
+
opts.on("-p","--path=[path]", "Install Accurev Git hook to specified path") { |path| options.path = path }
|
34
|
+
opts.on_tail("--version", "Print current version and exit") {options.command = :version }
|
35
|
+
opts.on_tail("-h","--help", "Print help message")
|
36
|
+
end
|
37
|
+
opts.parse!(args)
|
38
|
+
(puts opts and exit 0) if options.command == :help
|
39
|
+
options
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Installation
|
44
|
+
|
45
|
+
def initialize(repo)
|
46
|
+
install(repo)
|
47
|
+
end
|
48
|
+
|
49
|
+
def install(repo)
|
50
|
+
repo_hooks_dir = File.join(repo, '.git', 'hooks')
|
51
|
+
FileUtils.mkdir repo_hooks_dir unless File.exist? repo_hooks_dir
|
52
|
+
|
53
|
+
FileUtils.install(File.join(File.dirname(__FILE__), "hooks", "post-commit"), repo_hooks_dir, :mode => 0755)
|
54
|
+
FileUtils.install(File.join(File.dirname(__FILE__), "hooks", "pre-commit"), repo_hooks_dir, :mode => 0755)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# Copyright (c) 2011 Grayson Manley
|
2
|
+
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license
|
3
|
+
|
4
|
+
module AccuHook
|
5
|
+
module Accurev
|
6
|
+
class Commit
|
7
|
+
require File.dirname(__FILE__) + "/command"
|
8
|
+
|
9
|
+
def initialize(repository)
|
10
|
+
@command = AccuHook::Accurev::Command.new
|
11
|
+
last_git_commit = repository.commits.first
|
12
|
+
commit(last_git_commit)
|
13
|
+
end
|
14
|
+
|
15
|
+
def commit(last_git_commit)
|
16
|
+
last_git_commit.show.each do |diff|
|
17
|
+
case
|
18
|
+
when diff.new_file # Accurev add, then keep
|
19
|
+
@command.add(diff.a_path)
|
20
|
+
@command.keep(diff.a_path, last_git_commit.message)
|
21
|
+
when diff.deleted_file # accurev defunct
|
22
|
+
@command.defunct(diff.a_path, last_git_commit.message)
|
23
|
+
when diff.renamed_file # accurev defunct a_path, then add b_path (then keep)
|
24
|
+
puts "Renamed file detected"
|
25
|
+
@command.defunct(diff.a_path, last_git_commit.message)
|
26
|
+
@command.add(diff.b_path)
|
27
|
+
@command.keep(diff.b_path, last_git_commit.message)
|
28
|
+
else # Accurev regular keep
|
29
|
+
puts "Modified file detected"
|
30
|
+
@command.keep(diff.a_path, last_git_commit.message)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2011 Grayson Manley
|
4
|
+
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license
|
5
|
+
|
6
|
+
DEVELOPMENT_DIR = "/Users/tukaiz/projects/accurev_git_hooks"
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'rubygems'
|
10
|
+
require 'accuhook'
|
11
|
+
rescue LoadError => e
|
12
|
+
require File.join(DEVELOPMENT_DIR, "lib", "accuhook")
|
13
|
+
end
|
14
|
+
|
15
|
+
repository = Grit::Repo.new(File.join(File.dirname(__FILE__), "..", ".."))
|
16
|
+
AccuHook::Accurev::Commit.new(repository)
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright (c) 2011 Grayson Manley
|
4
|
+
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license
|
5
|
+
|
6
|
+
def logged_in?
|
7
|
+
system("accurev secinfo > /dev/null 2>&1")
|
8
|
+
end
|
9
|
+
|
10
|
+
raise "Please Login! (`accurev login`)" unless logged_in?
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Legit-the-Git
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Grayson Manley
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-10 00:00:00 -06:00
|
19
|
+
default_executable: accuhook
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: grit
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 3
|
33
|
+
- 0
|
34
|
+
version: 2.3.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Git hooks to help keep accurev and git in sync
|
38
|
+
email: gray.manley@gmail.com
|
39
|
+
executables:
|
40
|
+
- accuhook
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- LICENSE.txt
|
47
|
+
- legit-the-git.gemspec
|
48
|
+
- bin/accuhook
|
49
|
+
- lib/accuhook.rb
|
50
|
+
- lib/accuhook/command.rb
|
51
|
+
- lib/accuhook/command_line.rb
|
52
|
+
- lib/accuhook/commit.rb
|
53
|
+
- lib/accuhook/hooks/post-commit
|
54
|
+
- lib/accuhook/hooks/pre-commit
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://github.com/gmanley/Legit-the-Git
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.3.7
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Git accurev bridge
|
89
|
+
test_files: []
|
90
|
+
|