grog 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -21,6 +21,8 @@ A wrapper script for git-log - shows subject, time and author of each commit plu
21
21
  * Accept a commit range as a command line parameter
22
22
  * Fix tag/branch ambiguity issues
23
23
  * Show 'shadows' or remote branches (commit that is the latest in common with a remote branch)
24
+ * Distinguish commits by user with different color
25
+ * Read user default options from a .grog file
24
26
 
25
27
  == Copyright
26
28
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
data/bin/grog CHANGED
@@ -1,8 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
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)
4
+ puts Grog::GitLog.generate_parsing_arguments
@@ -4,16 +4,11 @@ Feature: default output of grog
4
4
  I want to see an overview of my recent commits
5
5
 
6
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"
7
+ Given a test git repo extracted from the "test_git_repo" tarball
13
8
  When I run grog on the test git repo
14
- Then the output should be
9
+ Then the output ignoring colour codes should be
15
10
  """
16
- Commit B
17
- Commit A
11
+ 6165a67 Commit B (Tom ten Thij) B(branch_b master) T(foo v2)
12
+ bf5b520 Commit A (Tom ten Thij) B(branch_a foo) T(v1)
18
13
 
19
14
  """
@@ -1,14 +1,43 @@
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}`
1
+ module GitHelpers
2
+ def set_root_path_variable
3
+ @root_dir ||= File.expand_path(File.dirname(__FILE__) + '/../..')
4
+ end
5
+
6
+ def set_repo_path_variable(name)
7
+ set_root_path_variable
8
+ unless @tmp_git_repo_dir
9
+ @features_dir = File.expand_path(File.dirname(__FILE__) + '/..')
10
+ @tmp_git_repo_dir = File.join(@features_dir, 'tmp', name)
11
+ end
12
+ end
13
+
14
+ def delete_temporary_test_repo
15
+ if File.exists?(@tmp_git_repo_dir)
16
+ `rm -rf #{@tmp_git_repo_dir}`
17
+ end
18
+ end
19
+
20
+ def untar_tarball_to_test_repo_location(tarball_name)
21
+ tarball_path = File.join(@root_dir, 'spec', tarball_name + '.tgz')
22
+ Dir.chdir(File.join(@features_dir, 'tmp'))
23
+ `tar zxf #{tarball_path}`
7
24
  end
25
+ end
26
+
27
+ Given /^a test git repo$/ do
28
+ name = 'git_repo'
29
+ set_repo_path_variable(name)
30
+ delete_temporary_test_repo(name)
8
31
  `mkdir #{@tmp_git_repo_dir}`
9
32
  `git init #{@tmp_git_repo_dir}`
10
33
  end
11
34
 
35
+ Given /^a test git repo extracted from the "([^\"]*)" tarball$/ do |tarball_name|
36
+ set_repo_path_variable(tarball_name)
37
+ delete_temporary_test_repo
38
+ untar_tarball_to_test_repo_location(tarball_name)
39
+ end
40
+
12
41
  Given /^the test git repo has a file called "([^\"]*)" containing "([^\"]*)"$/ do |filename, content|
13
42
  File.open(File.join(@tmp_git_repo_dir, filename), 'w') do |file|
14
43
  file.puts content
@@ -25,3 +54,5 @@ Given /^a checkout in the git repo with new branch called "([^\"]*)"$/ do |branc
25
54
  Dir.chdir(@tmp_git_repo_dir)
26
55
  `git checkout -b #{branch_name} 2> /dev/null`
27
56
  end
57
+
58
+ World(GitHelpers)
@@ -1,9 +1,15 @@
1
1
  When /^I run grog on the test git repo$/ do
2
2
  Dir.chdir(@tmp_git_repo_dir)
3
3
  grog_bin = File.join(@root_dir, 'bin', 'grog')
4
- @grog_output = `#{grog_bin}`
4
+ @grog_output = Grog::GitLog.generate_parsing_arguments
5
5
  end
6
6
 
7
7
  Then /^the output should be$/ do |expected_output|
8
8
  @grog_output.should == expected_output
9
9
  end
10
+
11
+ Then /^the output ignoring colour codes should be$/ do |expected_output|
12
+ colourless_output = @grog_output.gsub(/\e\[\d+m/, '')
13
+ colourless_output.should == expected_output
14
+ end
15
+
data/lib/grog/git_log.rb CHANGED
@@ -8,8 +8,14 @@ module Grog
8
8
  fetch_log
9
9
  end
10
10
 
11
- def self.print(options)
12
- puts self.new(options).to_s
11
+ def self.generate_parsing_arguments
12
+ options = Grog::Options.parse(ARGV)
13
+ generate(:number_of_commits_to_show => options.number_of_commits_to_show,
14
+ :show_datetimes => options.show_datetimes)
15
+ end
16
+
17
+ def self.generate(options)
18
+ self.new(options).to_s
13
19
  end
14
20
 
15
21
  def to_s
@@ -43,8 +49,8 @@ module Grog
43
49
  line += " T(" + Term::ANSIColor.cyan + tags.join(' ') + Term::ANSIColor.reset + ")"
44
50
  end
45
51
 
46
- line
47
- end
52
+ line + "\n"
53
+ end.join
48
54
  end
49
55
 
50
56
  protected
@@ -78,24 +84,42 @@ module Grog
78
84
  'git log --pretty=format:"%s" -n %d' % [format, @options[:number_of_commits_to_show]]
79
85
  end
80
86
 
81
- def self.hash_from_rev_names(rev_names)
87
+ def self.hash_from_rev_names(rev_names, ref_root)
82
88
  hash = Hash.new { |hash, key| hash[key] = [] }
89
+ # Instead of running the command for each rev, it should run the
90
+ # command with all of them
83
91
  rev_names.each do |rev_name|
84
- sha1 = GitLog.first_line_of_command("git rev-parse #{rev_name}")
92
+ sha1 = GitLog.first_line_of_command("git rev-parse #{ref_root}/#{rev_name}")
85
93
  hash[sha1] << rev_name
86
94
  end
87
95
  hash
88
96
  end
89
97
 
90
- def get_all_branches
91
- branch_names = GitLog.lines_of_command("git branch -a --no-color --no-track").
98
+ def branch_names_from_branch_command(type = :local)
99
+ case type
100
+ when :local
101
+ option = ''
102
+ ref = 'refs/heads'
103
+ when :remote
104
+ option = '-r '
105
+ ref = 'refs/remotes'
106
+ else
107
+ raise "Unknown type of branch: %s" % type
108
+ end
109
+ branch_names = GitLog.lines_of_command("git branch #{option}--no-color").
92
110
  map { |line| line[2..-1].split(' -> ').first }
93
- @branches = GitLog.hash_from_rev_names(branch_names)
111
+ GitLog.hash_from_rev_names(branch_names, ref)
112
+ end
113
+
114
+ def get_all_branches
115
+ local_branches = branch_names_from_branch_command(:local)
116
+ remote_branches = branch_names_from_branch_command(:remote)
117
+ @branches = local_branches.merge(remote_branches)
94
118
  end
95
119
 
96
120
  def get_all_tags
97
121
  tag_names = GitLog.lines_of_command("git tag")
98
- @tags = GitLog.hash_from_rev_names(tag_names)
122
+ @tags = GitLog.hash_from_rev_names(tag_names, 'refs/tags')
99
123
  end
100
124
 
101
125
  def fetch_log
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom ten Thij
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-04 00:00:00 +00:00
12
+ date: 2009-11-16 00:00:00 +00:00
13
13
  default_executable: grog
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency