lock_block 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ Ha ha, this is crap
4
+
3
5
  # Specify your gem's dependencies in lock_block.gemspec
4
6
  gemspec
data/README.md CHANGED
@@ -28,6 +28,10 @@ If a file is not specified, the program will read from STDIN.
28
28
  <td>--resolve, -r</td>
29
29
  <td>Update tags in annotation to mark blocks as up to date.</td>
30
30
  </tr>
31
+ <tr>
32
+ <td>--guard, -g path-to-repo</td>
33
+ <td>Installs pre-commit hook to repo to prevent committing broken locks.</td>
34
+ </tr>
31
35
  </tbody>
32
36
  </table>
33
37
 
data/bin/lock_block CHANGED
@@ -6,9 +6,11 @@ opts = Trollop::options do
6
6
  opt :lock, "Annotate input with lock hash", default: true
7
7
  opt :check, "Check input for broken locks"
8
8
  opt :resolve, "Update all lock tags in input"
9
+ opt :guard, "Path to repo which will be guarded with pre-commit hook", type: :string
9
10
  end
10
11
 
11
- input = ARGF.read
12
+ input = ARGF.read if !opts[:guard]
13
+
12
14
  if opts[:check]
13
15
  errs = LockBlock.broken_locks input
14
16
  if errs.any?
@@ -19,6 +21,17 @@ if opts[:check]
19
21
  end
20
22
  elsif opts[:resolve]
21
23
  puts LockBlock.resolve input
24
+ elsif opts[:guard]
25
+ repo = opts[:guard]
26
+ repo_hooks = File.absolute_path File.join(repo, '.git', 'hooks')
27
+ unless File.exists? repo_hooks
28
+ puts "Guard error: '#{repo}' is not the path of a git repo."
29
+ exit 1
30
+ end
31
+ here = File.dirname File.expand_path(__FILE__)
32
+ hook_source = File.absolute_path File.join(here, '..', 'lib', 'git', 'pre-commit')
33
+ File.symlink hook_source, File.join(repo_hooks, 'pre-commit')
34
+ puts "Added pre-commit hook to #{repo}"
22
35
  else
23
36
  puts LockBlock.lock input
24
37
  end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # Checks for out-of-date/broken locks
4
+
5
+ index_files=("`git diff --cached --name-only`")
6
+
7
+ for file in $index_files; do
8
+ bad_lock="`git show :$file | lock_block -c | cut -d: -f3`"
9
+ if [[ -n $bad_lock ]]; then
10
+ bad_exit=true
11
+ # lock_block operates on staged content; we want line numbers for physical files
12
+ line="`grep -n \"lock do $bad_lock\" $file | cut -d: -f1`"
13
+ locks=("${locks[@]} $file:$line:$bad_lock")
14
+ fi
15
+ done
16
+
17
+ if [[ -n $bad_exit ]]; then
18
+ echo -e "The following locks are broken:\n"
19
+ for lock in $locks; do
20
+ echo " $lock"
21
+ done
22
+ echo -e "\nPlease fix them before committing."
23
+ exit 1
24
+ fi
@@ -1,3 +1,3 @@
1
1
  module LockBlock
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lock_block.gemspec CHANGED
@@ -6,7 +6,7 @@ require 'lock_block/version'
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "lock_block"
8
8
  gem.version = LockBlock::VERSION
9
- gem.authors = ["Joe Nelson"]
9
+ gem.authors = ["Joe Nelson", "Ryland Herrick", "Chris Wilson"]
10
10
  gem.email = ["cred+github@begriffs.com"]
11
11
  gem.description = %q{Mark code blocks important, monitor them}
12
12
  gem.summary = %q{Provides command-line tool to annotate and check blocks of code}
metadata CHANGED
@@ -1,15 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lock_block
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Joe Nelson
9
+ - Ryland Herrick
10
+ - Chris Wilson
9
11
  autorequire:
10
12
  bindir: bin
11
13
  cert_chain: []
12
- date: 2012-11-04 00:00:00.000000000 Z
14
+ date: 2012-11-09 00:00:00.000000000 Z
13
15
  dependencies:
14
16
  - !ruby/object:Gem::Dependency
15
17
  name: trollop
@@ -42,6 +44,7 @@ files:
42
44
  - README.md
43
45
  - Rakefile
44
46
  - bin/lock_block
47
+ - lib/git/pre-commit
45
48
  - lib/lock_block.rb
46
49
  - lib/lock_block/version.rb
47
50
  - lock_block.gemspec