Legit-the-Git 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) <year> <copyright holders>
3
+ Copyright (c) 2011 Grayson Manley
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -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.2"
6
+ s.version = "0.0.3"
7
7
 
8
8
  s.summary = "Git accurev bridge"
9
9
  s.description = "Git hooks to help keep accurev and git in sync"
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
  "lib/accuhook/command_line.rb",
23
23
  "lib/accuhook/commit.rb",
24
24
  "lib/accuhook/hooks/post-commit",
25
- "lib/accuhook/hooks/pre-commit"
25
+ "lib/accuhook/hooks/post-receive"
26
26
  ]
27
27
  s.add_runtime_dependency("grit", ["~> 2.3.0"])
28
28
  end
@@ -1,6 +1,8 @@
1
1
  # Copyright (c) 2011 Grayson Manley
2
2
  # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license
3
3
 
4
+ require 'rubygems'
5
+ require 'accuhook'
4
6
  require 'optparse'
5
7
  require 'ostruct'
6
8
  require 'fileutils'
@@ -16,7 +18,7 @@ module AccuHook
16
18
  ret_val = AccuHook::Installation.new(options.path)
17
19
  exit 0
18
20
  when :version
19
- puts 'Version 0.0.1'
21
+ puts 'Version 0.0.3'
20
22
  exit 0
21
23
  end
22
24
  end
@@ -46,12 +48,21 @@ module AccuHook
46
48
  install(repo)
47
49
  end
48
50
 
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
51
+ def install(repo_path)
52
+ repository = Grit::Repo.new(repo_path)
52
53
 
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)
54
+ repo_hooks = File.join(repo_path, '.git', 'hooks')
55
+ accurev_repo = File.join(repo_path, '.git', 'accurev.git')
56
+ accurev_hooks = File.join(repo_path, '.git', 'accurev.git', 'hooks')
57
+
58
+ repository.fork_bare(accurev_repo, :shared => false, :mirror => true)
59
+ repository.remote_add("accurev", accurev_repo)
60
+
61
+ FileUtils.mkdir accurev_hooks unless File.exist? accurev_hooks
62
+ FileUtils.mkdir repo_hooks unless File.exist? repo_hooks
63
+
64
+ FileUtils.install(File.join(File.dirname(__FILE__), "hooks", "post-commit"), repo_hooks, :mode => 0755)
65
+ FileUtils.install(File.join(File.dirname(__FILE__), "hooks", "post-receive"), accurev_hooks, :mode => 0755)
55
66
  end
56
67
  end
57
68
  end
@@ -6,28 +6,30 @@ module AccuHook
6
6
  class Commit
7
7
  require File.dirname(__FILE__) + "/command"
8
8
 
9
- def initialize(repository)
9
+ def initialize(repository, commit_object)
10
10
  @command = AccuHook::Accurev::Command.new
11
- last_git_commit = repository.commits.first
12
- commit(last_git_commit)
11
+ puts commit_object.inspect
12
+ commit!(commit_object, repository)
13
13
  end
14
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)
15
+ def commit!(commit_object, repository)
16
+ commit_object.each do |commit|
17
+ commit.show.each do |diff|
18
+ case
19
+ when diff.new_file # Accurev add, then keep
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
+ @command.defunct("#{repository.working_dir}/#{diff.a_path}", commit.message)
24
+ when diff.renamed_file # accurev defunct a_path, then add b_path (then keep)
25
+ puts "Renamed file detected"
26
+ @command.defunct("#{repository.working_dir}/#{diff.a_path}", commit.message)
27
+ @command.add("#{repository.working_dir}/#{diff.b_path}")
28
+ @command.keep("#{repository.working_dir}/#{diff.b_path}", commit.message)
29
+ else # Accurev regular keep
30
+ puts "Modified file detected"
31
+ @command.keep("#{repository.working_dir}/#{diff.a_path}", commit.message)
32
+ end
31
33
  end
32
34
  end
33
35
  end
@@ -3,14 +3,8 @@
3
3
  # Copyright (c) 2011 Grayson Manley
4
4
  # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license
5
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")
6
+ def logged_in?
7
+ system("accurev secinfo > /dev/null 2>&1")
13
8
  end
14
9
 
15
- repository = Grit::Repo.new(File.join(File.dirname(__FILE__), "..", ".."))
16
- AccuHook::Accurev::Commit.new(repository)
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 'accuhook'
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
+ AccuHook::Accurev::Commit.new(repository, @commits.reverse)
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: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
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-01-10 00:00:00 -06:00
18
+ date: 2011-01-12 00:00:00 -06:00
19
19
  default_executable: accuhook
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -51,7 +51,7 @@ files:
51
51
  - lib/accuhook/command_line.rb
52
52
  - lib/accuhook/commit.rb
53
53
  - lib/accuhook/hooks/post-commit
54
- - lib/accuhook/hooks/pre-commit
54
+ - lib/accuhook/hooks/post-receive
55
55
  has_rdoc: true
56
56
  homepage: http://github.com/gmanley/Legit-the-Git
57
57
  licenses:
@@ -1,10 +0,0 @@
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?