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.
- data/lib/git-story +10 -7
- 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
|
-
|
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.
|
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
|
-
|
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(
|
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(
|
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
|