legit-the-git 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/bin/legit-the-git CHANGED
@@ -6,4 +6,4 @@
6
6
  require 'rubygems'
7
7
  require 'legit-the-git'
8
8
 
9
- LegitGit::CommandLine.execute(ARGV)
9
+ LegitGit::CommandLine.execute(ARGV[0])
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "legit-the-git"
6
- s.version = "0.0.4"
6
+ s.version = "0.0.5"
7
7
 
8
8
  s.summary = "Git accurev bridge"
9
9
  s.description = "Git hooks to help keep accurev and git in sync"
@@ -6,32 +6,29 @@ module LegitGit
6
6
  class Command
7
7
  require "shellwords"
8
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 \"#{message}\" \"#{file_path}\"")
23
+ end
24
+
9
25
  private
10
26
  def execute(command)
11
27
  args = Shellwords.split(command)
12
28
  escaped_args = args.map {|arg| Shellwords.escape(arg)}
13
29
  sub_command = Shellwords.join(escaped_args)
14
- #puts "Running accurev #{sub_command}"
15
30
  system("accurev #{sub_command}")
16
31
  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
32
  end
36
33
  end
37
34
  end
@@ -3,65 +3,78 @@
3
3
 
4
4
  require 'rubygems'
5
5
  require 'legit-the-git'
6
- require 'optparse'
7
- require 'ostruct'
8
6
  require 'fileutils'
9
7
 
10
8
  module LegitGit
11
9
  class CommandLine
10
+
12
11
  # Parse command line options and execute
13
12
  def self.execute(args)
14
- options = parse_options(args)
15
13
 
16
- case options.command
17
- when :install
18
- ret_val = LegitGit::Installation.new(options.path)
14
+ help = <<-EOS
15
+ Usage #{File.basename $0} [--version] [--help] <command>
16
+
17
+ Commands:
18
+ install Install the Accurev Git hook into the current directory
19
+ uninstall Remove legit-the-git from the current repo
20
+
21
+ Workflow:
22
+ Once installed commit your changes like usual. When you would like to push
23
+ those changes to accurev, just run `git push accurev`. This will sync new
24
+ commits from the current branch to the accurev server. Just make sure you
25
+ are logged into accurev!
26
+
27
+ EOS
28
+
29
+ case args
30
+ when "install"
31
+ installation = LegitGit::Installation.new(Dir.pwd)
32
+ installation.install
33
+ puts 'Successfully installed!'
34
+ puts "Run #{File.basename $0} --help for usage."
19
35
  exit 0
20
- when :version
21
- puts 'Version 0.0.4'
36
+ when "uninstall"
37
+ installation = LegitGit::Installation.new(Dir.pwd)
38
+ installation.uninstall
39
+ puts 'Successfully uninstalled!'
22
40
  exit 0
41
+ when "--version"
42
+ puts "0.0.5"
43
+ exit 0
44
+ else
45
+ puts help
23
46
  end
24
47
  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
48
  end
44
49
 
45
50
  class Installation
51
+ # Refactor!
52
+
53
+ def initialize(repo_path)
54
+ @repository = Grit::Repo.new(repo_path)
55
+ @accurev_repo = File.join(repo_path, '.git', 'accurev.git')
46
56
 
47
- def initialize(repo)
48
- install(repo)
57
+ @accurev_hooks = File.join(repo_path, '.git', 'accurev.git', 'hooks')
58
+ @repo_hooks = File.join(repo_path, '.git', 'accurev.git', 'hooks')
49
59
  end
50
60
 
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')
61
+ def install
62
+ @repository.fork_bare(@accurev_repo, :shared => false, :mirror => true)
63
+ @repository.remote_add("accurev", @accurev_repo)
56
64
 
57
- repository.fork_bare(accurev_repo, :shared => false, :mirror => true)
58
- repository.remote_add("accurev", accurev_repo)
65
+ FileUtils.mkdir_p([@accurev_hooks, @repo_hooks])
59
66
 
60
- FileUtils.mkdir accurev_hooks unless File.exist? accurev_hooks
61
- FileUtils.mkdir repo_hooks unless File.exist? repo_hooks
67
+ FileUtils.install(File.join(File.dirname(__FILE__), "hooks", "post-commit"), @repo_hooks, :mode => 0755)
68
+ FileUtils.install(File.join(File.dirname(__FILE__), "hooks", "pre-receive"), @accurev_hooks, :mode => 0755)
69
+ end
70
+
71
+ def uninstall
72
+ unless @repository.remotes.select {|r| r.name =~ /accurev/}.empty?
73
+ git = Grit::Git.new(File.expand_path(File.join(Dir.pwd, '.git/')))
74
+ git.native(:remote, {}, 'rm', 'accurev')
75
+ end
62
76
 
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)
77
+ FileUtils.rm_rf([@accurev_repo, File.join(@repo_hooks, "hooks", "post-commit")])
65
78
  end
66
79
  end
67
80
  end
@@ -7,12 +7,13 @@ module LegitGit
7
7
  require File.dirname(__FILE__) + "/command"
8
8
 
9
9
  def initialize(repository, commit_object)
10
- @command = LegitGit::Accurev::Command.new
10
+ @command = Command.new
11
11
  commit!(commit_object, repository)
12
12
  end
13
13
 
14
14
  def commit!(commit_object, repository)
15
15
  commit_object.each do |commit|
16
+ $stdout.puts "\e[\033[0;36mSyncing Commit \e[\033[0;32m#{commit.id_abbrev}\e[0m\n\e[\033[0;33m#{commit.message}\e[0m"
16
17
  commit.show.each do |diff|
17
18
  case
18
19
  when diff.new_file # Accurev add, then keep
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legit-the-git
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Grayson Manley
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-07 00:00:00 -06:00
18
+ date: 2011-02-22 00:00:00 -06:00
19
19
  default_executable: legit-the-git
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency