grog 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ features/tmp
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Tom ten Thij
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = grog
2
+
3
+ A wrapper script for git-log - shows subject, time and author of each commit plus branches and tags
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 Tom ten Thij. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "grog"
8
+ gem.summary = %Q{A wrapper script for git-log - shows subject, time and author of each commit plus branches and tags}
9
+ gem.description = %Q{A wrapper script for git-log}
10
+ gem.email = "git@tomtenthij.nl"
11
+ gem.homepage = "http://github.com/tomtt/grog"
12
+ gem.authors = ["Tom ten Thij"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_development_dependency "cucumber", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ begin
37
+ require 'cucumber/rake/task'
38
+ Cucumber::Rake::Task.new(:features)
39
+
40
+ task :features => :check_dependencies
41
+ rescue LoadError
42
+ task :features do
43
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
44
+ end
45
+ end
46
+
47
+ task :default => :spec
48
+
49
+ require 'rake/rdoctask'
50
+ Rake::RDocTask.new do |rdoc|
51
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
52
+
53
+ rdoc.rdoc_dir = 'rdoc'
54
+ rdoc.title = "grog #{version}"
55
+ rdoc.rdoc_files.include('README*')
56
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/bin/grog ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'grog'
4
+
5
+ # puts `git log --pretty=format:"%x1b[33m%h%Creset %s %Cgreen(%an)%Creset"`
6
+ options = Grog::Options.parse(ARGV)
7
+ Grog::GitLog.print(:number_of_commits_to_show => options.number_of_commits_to_show,
8
+ :show_datetimes => options.show_datetimes)
@@ -0,0 +1,19 @@
1
+ Feature: default output of grog
2
+ In order to find out the state of my git repository
3
+ As a developer
4
+ I want to see an overview of my recent commits
5
+
6
+ Scenario: running grog with no options
7
+ Given a test git repo
8
+ And the test git repo has a file called "file_a" containing "I am A"
9
+ And a commit of all changes to the test git repo with message "Commit A"
10
+ And a checkout in the git repo with new branch called "branch_a"
11
+ And the test git repo has a file called "file_b" containing "I am B"
12
+ And a commit of all changes to the test git repo with message "Commit B"
13
+ When I run grog on the test git repo
14
+ Then the output should be
15
+ """
16
+ Commit B
17
+ Commit A
18
+
19
+ """
@@ -0,0 +1,3 @@
1
+ Then /^debugger$/ do
2
+ debugger
3
+ end
@@ -0,0 +1,27 @@
1
+ Given /^a test git repo$/ do
2
+ features_dir = File.expand_path(File.dirname(__FILE__) + '/..')
3
+ @root_dir = File.expand_path(File.dirname(__FILE__) + '/../..')
4
+ @tmp_git_repo_dir = File.join(features_dir, 'tmp', 'git_repo')
5
+ if File.exists?(@tmp_git_repo_dir)
6
+ `rm -rf #{@tmp_git_repo_dir}`
7
+ end
8
+ `mkdir #{@tmp_git_repo_dir}`
9
+ `git init #{@tmp_git_repo_dir}`
10
+ end
11
+
12
+ Given /^the test git repo has a file called "([^\"]*)" containing "([^\"]*)"$/ do |filename, content|
13
+ File.open(File.join(@tmp_git_repo_dir, filename), 'w') do |file|
14
+ file.puts content
15
+ end
16
+ end
17
+
18
+ Given /^a commit of all changes to the test git repo with message "([^\"]*)"$/ do |message|
19
+ Dir.chdir(@tmp_git_repo_dir)
20
+ `git add -A .`
21
+ `git commit -m "#{message}"`
22
+ end
23
+
24
+ Given /^a checkout in the git repo with new branch called "([^\"]*)"$/ do |branch_name|
25
+ Dir.chdir(@tmp_git_repo_dir)
26
+ `git checkout -b #{branch_name} 2> /dev/null`
27
+ end
@@ -0,0 +1,9 @@
1
+ When /^I run grog on the test git repo$/ do
2
+ Dir.chdir(@tmp_git_repo_dir)
3
+ grog_bin = File.join(@root_dir, 'bin', 'grog')
4
+ @grog_output = `#{grog_bin}`
5
+ end
6
+
7
+ Then /^the output should be$/ do |expected_output|
8
+ @grog_output.should == expected_output
9
+ end
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'grog'
3
+
4
+ require 'spec/expectations'
5
+ require 'ruby-debug'
data/grog.gemspec ADDED
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{grog}
8
+ s.version = ""
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Tom ten Thij"]
12
+ s.date = %q{2009-11-01}
13
+ s.default_executable = %q{grog}
14
+ s.description = %q{A wrapper script for git-log}
15
+ s.email = %q{git@tomtenthij.nl}
16
+ s.executables = ["grog"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "bin/grog",
28
+ "features/grog.feature",
29
+ "features/step_definitions/grog_steps.rb",
30
+ "features/support/env.rb",
31
+ "grog.gemspec",
32
+ "lib/grog.rb",
33
+ "spec/grog_spec.rb",
34
+ "spec/spec.opts",
35
+ "spec/spec_helper.rb"
36
+ ]
37
+ s.homepage = %q{http://github.com/tomtt/grog}
38
+ s.rdoc_options = ["--charset=UTF-8"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.3.5}
41
+ s.summary = %q{A wrapper script for git-log - shows subject, time and author of each commit plus branches and tags}
42
+ s.test_files = [
43
+ "spec/grog_spec.rb",
44
+ "spec/spec_helper.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
52
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
53
+ s.add_development_dependency(%q<cucumber>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
56
+ s.add_dependency(%q<cucumber>, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
60
+ s.add_dependency(%q<cucumber>, [">= 0"])
61
+ end
62
+ end
63
+
@@ -0,0 +1,107 @@
1
+ require 'term/ansicolor'
2
+
3
+ module Grog
4
+ class GitLog
5
+ @@placeholders = %w{H P an ai s}
6
+ def initialize(options)
7
+ @options = options
8
+ fetch_log
9
+ end
10
+
11
+ def self.print(options)
12
+ puts self.new(options).to_s
13
+ end
14
+
15
+ def to_s
16
+ @log_lines.map do |line|
17
+ values = Hash[*@@placeholders.zip(line.split('|||')).flatten]
18
+
19
+ sha = GitLog.short_sha1(values['H'])
20
+ date = GitLog.nice_date_format(values['ai'])
21
+ subject = values['s']
22
+ author = values['an']
23
+ branches = branches(values['H'])
24
+ tags = tags(values['H'])
25
+
26
+ line =
27
+ Term::ANSIColor.yellow + sha + ' '
28
+
29
+ if @options[:show_datetimes]
30
+ line +=
31
+ Term::ANSIColor.green + date + ' '
32
+ end
33
+
34
+ line +=
35
+ Term::ANSIColor.reset + subject + ' ' +
36
+ Term::ANSIColor.green + "(#{author})" + Term::ANSIColor.reset
37
+
38
+ unless branches.empty?
39
+ line += " B(" + Term::ANSIColor.red + branches.join(' ') + Term::ANSIColor.reset + ")"
40
+ end
41
+
42
+ unless tags.empty?
43
+ line += " T(" + Term::ANSIColor.cyan + tags.join(' ') + Term::ANSIColor.reset + ")"
44
+ end
45
+
46
+ line
47
+ end
48
+ end
49
+
50
+ protected
51
+
52
+ def branches(sha1)
53
+ @branches[sha1]
54
+ end
55
+
56
+ def tags(sha1)
57
+ @tags[sha1]
58
+ end
59
+
60
+ def self.short_sha1(sha1)
61
+ sha1[0,7]
62
+ end
63
+
64
+ def self.nice_date_format(date)
65
+ DateTime.parse(date).strftime('%Y-%m-%d %H:%M')
66
+ end
67
+
68
+ def self.lines_of_command(command)
69
+ `#{command}`.split("\n")
70
+ end
71
+
72
+ def self.first_line_of_command(command)
73
+ `#{command}`.split("\n").first
74
+ end
75
+
76
+ def git_log_command
77
+ format = @@placeholders.map{ |p| "%" + p }.join('|||')
78
+ 'git log --pretty=format:"%s" -n %d' % [format, @options[:number_of_commits_to_show]]
79
+ end
80
+
81
+ def self.hash_from_rev_names(rev_names)
82
+ hash = Hash.new { |hash, key| hash[key] = [] }
83
+ rev_names.each do |rev_name|
84
+ sha1 = GitLog.first_line_of_command("git-rev-parse #{rev_name}")
85
+ hash[sha1] << rev_name
86
+ end
87
+ hash
88
+ end
89
+
90
+ def get_all_branches
91
+ branch_names = GitLog.lines_of_command("git branch -a --no-color --no-track").
92
+ map { |line| line[2..-1].split(' -> ').first }
93
+ @branches = GitLog.hash_from_rev_names(branch_names)
94
+ end
95
+
96
+ def get_all_tags
97
+ tag_names = GitLog.lines_of_command("git-tag")
98
+ @tags = GitLog.hash_from_rev_names(tag_names)
99
+ end
100
+
101
+ def fetch_log
102
+ get_all_branches
103
+ get_all_tags
104
+ @log_lines = GitLog.lines_of_command(git_log_command)
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,27 @@
1
+ require 'optparse'
2
+
3
+ module Grog
4
+ class Options
5
+ attr_accessor :number_of_commits_to_show, :show_datetimes
6
+
7
+ def self.parse(argv)
8
+ Options.new(argv)
9
+ end
10
+
11
+ def initialize(argv)
12
+ @opts = OptionParser.new
13
+
14
+ @number_of_commits_to_show = 10
15
+ @opts.on("-n=N", "number of commits to show", Integer) { |val| @number_of_commits_to_show = val }
16
+
17
+ @show_datetimes = false
18
+ @opts.on("-d", "show datetimes") { @show_datetimes = true }
19
+ @opts.on_tail("-h", "--help", "Show this message") do
20
+ puts @opts
21
+ exit
22
+ end
23
+
24
+ @rest = @opts.parse(argv)
25
+ end
26
+ end
27
+ end
data/lib/grog.rb ADDED
@@ -0,0 +1,5 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'grog/options'
5
+ require 'grog/git_log'
@@ -0,0 +1,6 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'grog/git_log'
3
+
4
+ describe Grog::GitLog do
5
+ it "should do stuff"
6
+ end
@@ -0,0 +1,47 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'grog/options'
3
+
4
+ describe Grog::Options do
5
+ describe "number of commits to show" do
6
+ it "should be set by the -n argument" do
7
+ options = Grog::Options.parse(%w{-n 34})
8
+ options.number_of_commits_to_show.should == 34
9
+ end
10
+
11
+ it "should be 10 by default" do
12
+ Grog::Options.new([]).number_of_commits_to_show.should == 10
13
+ end
14
+ end
15
+
16
+ describe "show datetimes" do
17
+ it "should be set if the -d flag is passed" do
18
+ options = Grog::Options.parse(%w{-d})
19
+ options.show_datetimes.should be_true
20
+ end
21
+
22
+ it "should be false by default" do
23
+ Grog::Options.new([]).show_datetimes.should be_false
24
+ end
25
+ end
26
+
27
+ describe "help" do
28
+ it "should print help info if the --help flag is passed" do
29
+ pending "how to ignore exception thrown by exit?"
30
+ options = Grog::Options.new([])
31
+ $stdout.should_receive(:write).with(options.instance_variable_get('@opts').to_s)
32
+ Grog::Options.new(%w{--help})
33
+ end
34
+
35
+ it "should print help info if the -h flag is passed" do
36
+ pending "how to ignore exception thrown by exit?"
37
+ options = Grog::Options.new([])
38
+ $stdout.should_receive(:write).with(options.instance_variable_get('@opts').to_s)
39
+ Grog::Options.new(%w{-h})
40
+ end
41
+
42
+ it "should exit" do
43
+ $stdout.stub!(:write)
44
+ lambda { Grog::Options.new(%w{--help}) }.should raise_error(SystemExit)
45
+ end
46
+ end
47
+ end
data/spec/grog_spec.rb ADDED
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Grog" do
4
+ it "fails" do
5
+ pending
6
+ fail "hey buddy, you should probably rename this file and start specing for real"
7
+ end
8
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'grog'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+ require 'ruby-debug'
7
+
8
+ Spec::Runner.configure do |config|
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tom ten Thij
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-02 00:00:00 +00:00
13
+ default_executable: grog
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.9
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: cucumber
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: A wrapper script for git-log
36
+ email: git@tomtenthij.nl
37
+ executables:
38
+ - grog
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - bin/grog
52
+ - features/grog.feature
53
+ - features/step_definitions/common_steps.rb
54
+ - features/step_definitions/git_steps.rb
55
+ - features/step_definitions/grog_steps.rb
56
+ - features/support/env.rb
57
+ - grog.gemspec
58
+ - lib/grog.rb
59
+ - lib/grog/git_log.rb
60
+ - lib/grog/options.rb
61
+ - spec/grog/git_log_spec.rb
62
+ - spec/grog/options_spec.rb
63
+ - spec/grog_spec.rb
64
+ - spec/spec.opts
65
+ - spec/spec_helper.rb
66
+ has_rdoc: true
67
+ homepage: http://github.com/tomtt/grog
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --charset=UTF-8
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ requirements: []
88
+
89
+ rubyforge_project:
90
+ rubygems_version: 1.3.5
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: A wrapper script for git-log - shows subject, time and author of each commit plus branches and tags
94
+ test_files:
95
+ - spec/grog/git_log_spec.rb
96
+ - spec/grog/options_spec.rb
97
+ - spec/grog_spec.rb
98
+ - spec/spec_helper.rb