git-story 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/git-story +10 -7
  2. metadata +1 -1
data/lib/git-story CHANGED
@@ -5,7 +5,7 @@ require 'grit'
5
5
  require 'trollop'
6
6
 
7
7
  def print(commit, suffix)
8
- puts "#{commit.committed_date} #{commit.sha} #{commit.message} #{commit.committer} #{suffix}"
8
+ puts "#{commit.committed_date} #{commit.sha} #{commit.message.strip.split("\n").first} #{commit.committer} #{suffix}"
9
9
  end
10
10
 
11
11
  def print_story(current_commit, head, merge_commits, merge_commits_directions)
@@ -26,7 +26,7 @@ end
26
26
  def story(searched_sha, branch, repo)
27
27
  merge_commits = []
28
28
  merge_commits_directions = []
29
- processed_merge_commits = Set.new
29
+ processed_shas = Set.new
30
30
 
31
31
  head = repo.commits(branch).first
32
32
  next_commit = head
@@ -34,15 +34,17 @@ def story(searched_sha, branch, repo)
34
34
 
35
35
  while(!finished)
36
36
  current_commit = next_commit
37
+
38
+ #print travel path if the current commit is the one we're looking for
37
39
  print_story(current_commit, head, merge_commits, merge_commits_directions) if(current_commit.sha == searched_sha)
38
40
 
39
41
  #go back to previous merge commit and go to its next parent
40
- if(current_commit.parents.empty? or processed_merge_commits.include?(current_commit) or current_commit.sha == searched_sha)
42
+ if(processed_shas.include?(current_commit.sha) or current_commit.parents.empty? or current_commit.sha == searched_sha)
41
43
  done = false
42
44
  while(!done and merge_commits.any?)
43
45
  merge_commits_directions[merge_commits_directions.length - 1] += 1
44
46
  if(merge_commits_directions.last == merge_commits.last.parents.length)
45
- processed_merge_commits << merge_commits.pop
47
+ processed_shas << merge_commits.pop.sha
46
48
  merge_commits_directions.pop
47
49
  else
48
50
  done = true
@@ -57,8 +59,9 @@ def story(searched_sha, branch, repo)
57
59
  merge_commits_directions << 0
58
60
  next_commit = current_commit.parents[0]
59
61
 
60
- #standard commit - go to first parent
62
+ #standard commit - add current commit to set of processed commits and go to first parent
61
63
  else
64
+ processed_shas << current_commit.sha
62
65
  next_commit = current_commit.parents[0]
63
66
  end
64
67
  end
@@ -72,12 +75,12 @@ end
72
75
  git_directory = `git rev-parse --show-toplevel`
73
76
  repo = Grit::Repo.new(git_directory.chomp!)
74
77
 
75
- if(repo.branches.index{|branch| branch.name.eql?(opts[:branch])}.nil?)
78
+ if(`git branch | grep -w #{opts[:branch]}` == '')
76
79
  puts "Error: the specified branch does not exist."
77
80
  exit(-1)
78
81
  end
79
82
 
80
- if(repo.commits(opts[:branch], false).index{|commit| commit.sha.eql?(opts[:commit])}.nil?)
83
+ if(`git rev-list #{opts[:branch]} | grep -w #{opts[:commit]}` == '')
81
84
  puts "Error: the specified commit does not exist in the specified branch."
82
85
  exit(-1)
83
86
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-story
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: