legit-the-git 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +21 -0
- data/bin/legit-the-git +9 -0
- data/legit-the-git.gemspec +28 -0
- data/lib/legit-the-git.rb +7 -0
- data/lib/legit-the-git/command.rb +37 -0
- data/lib/legit-the-git/command_line.rb +67 -0
- data/lib/legit-the-git/commit.rb +39 -0
- data/lib/legit-the-git/hooks/post-commit +10 -0
- data/lib/legit-the-git/hooks/pre-receive +20 -0
- metadata +90 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2011 Grayson Manley
|
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/legit-the-git
ADDED
@@ -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.4"
|
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 = "legit-the-git"
|
15
|
+
s.executables = ["legit-the-git"]
|
16
|
+
s.files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"legit-the-git.gemspec",
|
19
|
+
"bin/legit-the-git",
|
20
|
+
"lib/legit-the-git.rb",
|
21
|
+
"lib/legit-the-git/command.rb",
|
22
|
+
"lib/legit-the-git/command_line.rb",
|
23
|
+
"lib/legit-the-git/commit.rb",
|
24
|
+
"lib/legit-the-git/hooks/post-commit",
|
25
|
+
"lib/legit-the-git/hooks/pre-receive"
|
26
|
+
]
|
27
|
+
s.add_runtime_dependency("grit", ["~> 2.3.0"])
|
28
|
+
end
|
@@ -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__) + '/legit-the-git/command_line'
|
7
|
+
require File.dirname(__FILE__) + '/legit-the-git/commit'
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Copyright (c) 2011 Grayson Manley
|
2
|
+
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license
|
3
|
+
|
4
|
+
module LegitGit
|
5
|
+
module Accurev
|
6
|
+
class Command
|
7
|
+
require "shellwords"
|
8
|
+
|
9
|
+
private
|
10
|
+
def execute(command)
|
11
|
+
args = Shellwords.split(command)
|
12
|
+
escaped_args = args.map {|arg| Shellwords.escape(arg)}
|
13
|
+
sub_command = Shellwords.join(escaped_args)
|
14
|
+
#puts "Running accurev #{sub_command}"
|
15
|
+
system("accurev #{sub_command}")
|
16
|
+
end
|
17
|
+
|
18
|
+
class << self
|
19
|
+
def add(file_path)
|
20
|
+
if File.directory?(file_path) # Recursively add directory (`accurev add -x -R {Dir}`)
|
21
|
+
execute("add -x -R \"#{file_path}\"")
|
22
|
+
else # Add single file (`accurev add {File}`)
|
23
|
+
execute("add \"#{file_path}\"")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def keep(file_path, message)
|
28
|
+
execute("keep -c \"#{message}\" \"#{file_path}\"")
|
29
|
+
end
|
30
|
+
|
31
|
+
def defunct(file_path, message)
|
32
|
+
execute("defunct -c \"#{@last_commit_message}\" \"#{diff.a_path}\"")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,67 @@
|
|
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 'legit-the-git'
|
6
|
+
require 'optparse'
|
7
|
+
require 'ostruct'
|
8
|
+
require 'fileutils'
|
9
|
+
|
10
|
+
module LegitGit
|
11
|
+
class CommandLine
|
12
|
+
# Parse command line options and execute
|
13
|
+
def self.execute(args)
|
14
|
+
options = parse_options(args)
|
15
|
+
|
16
|
+
case options.command
|
17
|
+
when :install
|
18
|
+
ret_val = LegitGit::Installation.new(options.path)
|
19
|
+
exit 0
|
20
|
+
when :version
|
21
|
+
puts 'Version 0.0.4'
|
22
|
+
exit 0
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def self.parse_options(args)
|
28
|
+
options = OpenStruct.new
|
29
|
+
options.command = :help
|
30
|
+
options.path = Dir.pwd
|
31
|
+
|
32
|
+
opts = OptionParser.new do |opts|
|
33
|
+
opts.banner = "Usage #{File.basename $0} [options]"
|
34
|
+
opts.on_head("-i","--install", "Install Accurev Git hook in current dir") { options.command = :install }
|
35
|
+
opts.on("-p","--path=[path]", "Install Accurev Git hook to specified path") { |path| options.path = path }
|
36
|
+
opts.on_tail("--version", "Print current version and exit") {options.command = :version }
|
37
|
+
opts.on_tail("-h","--help", "Print help message")
|
38
|
+
end
|
39
|
+
opts.parse!(args)
|
40
|
+
(puts opts and exit 0) if options.command == :help
|
41
|
+
options
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class Installation
|
46
|
+
|
47
|
+
def initialize(repo)
|
48
|
+
install(repo)
|
49
|
+
end
|
50
|
+
|
51
|
+
def install(repo_path)
|
52
|
+
repository = Grit::Repo.new(repo_path)
|
53
|
+
repo_hooks = File.join(repo_path, '.git', 'hooks')
|
54
|
+
accurev_repo = File.join(repo_path, '.git', 'accurev.git')
|
55
|
+
accurev_hooks = File.join(repo_path, '.git', 'accurev.git', 'hooks')
|
56
|
+
|
57
|
+
repository.fork_bare(accurev_repo, :shared => false, :mirror => true)
|
58
|
+
repository.remote_add("accurev", accurev_repo)
|
59
|
+
|
60
|
+
FileUtils.mkdir accurev_hooks unless File.exist? accurev_hooks
|
61
|
+
FileUtils.mkdir repo_hooks unless File.exist? repo_hooks
|
62
|
+
|
63
|
+
FileUtils.install(File.join(File.dirname(__FILE__), "hooks", "post-commit"), repo_hooks, :mode => 0755)
|
64
|
+
FileUtils.install(File.join(File.dirname(__FILE__), "hooks", "pre-receive"), accurev_hooks, :mode => 0755)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Copyright (c) 2011 Grayson Manley
|
2
|
+
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license
|
3
|
+
|
4
|
+
module LegitGit
|
5
|
+
module Accurev
|
6
|
+
class Commit
|
7
|
+
require File.dirname(__FILE__) + "/command"
|
8
|
+
|
9
|
+
def initialize(repository, commit_object)
|
10
|
+
@command = LegitGit::Accurev::Command.new
|
11
|
+
commit!(commit_object, repository)
|
12
|
+
end
|
13
|
+
|
14
|
+
def commit!(commit_object, repository)
|
15
|
+
commit_object.each do |commit|
|
16
|
+
commit.show.each do |diff|
|
17
|
+
case
|
18
|
+
when diff.new_file # Accurev add, then keep
|
19
|
+
puts "New file detected"
|
20
|
+
@command.add("#{repository.working_dir}/#{diff.a_path}")
|
21
|
+
@command.keep("#{repository.working_dir}/#{diff.a_path}", commit.message)
|
22
|
+
when diff.deleted_file # accurev defunct
|
23
|
+
puts "Deleted file detected"
|
24
|
+
@command.defunct("#{repository.working_dir}/#{diff.a_path}", commit.message)
|
25
|
+
when diff.renamed_file # accurev defunct a_path, then add b_path (then keep)
|
26
|
+
puts "Renamed file detected"
|
27
|
+
@command.defunct("#{repository.working_dir}/#{diff.a_path}", commit.message)
|
28
|
+
@command.add("#{repository.working_dir}/#{diff.b_path}")
|
29
|
+
@command.keep("#{repository.working_dir}/#{diff.b_path}", commit.message)
|
30
|
+
else # Accurev regular keep
|
31
|
+
puts "Modified file detected"
|
32
|
+
@command.keep("#{repository.working_dir}/#{diff.a_path}", commit.message)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -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
|
+
puts "Remember to login before you push to accurev! (`accurev login`)" unless logged_in?
|
@@ -0,0 +1,20 @@
|
|
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
|
+
input = $stdin.gets
|
6
|
+
args = input.split(" ")
|
7
|
+
old_head_ref = args[0]
|
8
|
+
new_head_ref = args[1]
|
9
|
+
|
10
|
+
require 'rubygems'
|
11
|
+
require 'legit-the-git'
|
12
|
+
|
13
|
+
repository = Grit::Repo.new(File.join(File.dirname(__FILE__), "..", "..", ".."))
|
14
|
+
|
15
|
+
@commits = []
|
16
|
+
repository.commit_deltas_from(repository, old_head_ref, new_head_ref).each do |commit|
|
17
|
+
@commits << commit
|
18
|
+
end
|
19
|
+
|
20
|
+
LegitGit::Accurev::Commit.new(repository, @commits.reverse)
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: legit-the-git
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Grayson Manley
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-07 00:00:00 -06:00
|
19
|
+
default_executable: legit-the-git
|
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
|
+
- legit-the-git
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- LICENSE.txt
|
47
|
+
- legit-the-git.gemspec
|
48
|
+
- bin/legit-the-git
|
49
|
+
- lib/legit-the-git.rb
|
50
|
+
- lib/legit-the-git/command.rb
|
51
|
+
- lib/legit-the-git/command_line.rb
|
52
|
+
- lib/legit-the-git/commit.rb
|
53
|
+
- lib/legit-the-git/hooks/post-commit
|
54
|
+
- lib/legit-the-git/hooks/pre-receive
|
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.5.0
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Git accurev bridge
|
89
|
+
test_files: []
|
90
|
+
|