git-story 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/git-story +85 -0
- metadata +79 -0
data/lib/git-story
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
require 'grit'
|
5
|
+
require 'trollop'
|
6
|
+
|
7
|
+
def print(commit, suffix)
|
8
|
+
puts "#{commit.committed_date} #{commit.sha} #{commit.message} #{commit.committer} #{suffix}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def print_story(current_commit, head, merge_commits, merge_commits_directions)
|
12
|
+
puts "\n"
|
13
|
+
puts "Possible path"
|
14
|
+
puts "-------------"
|
15
|
+
|
16
|
+
print(current_commit, 'START')
|
17
|
+
i = (merge_commits.length - 1)
|
18
|
+
while(i >= 0)
|
19
|
+
#direction 0 indicates there was no branch change
|
20
|
+
print(merge_commits[i], 'MERGE') if(merge_commits_directions[i] != 0)
|
21
|
+
i -= 1
|
22
|
+
end
|
23
|
+
print(head, 'HEAD')
|
24
|
+
end
|
25
|
+
|
26
|
+
def story(searched_sha, branch, repo)
|
27
|
+
merge_commits = []
|
28
|
+
merge_commits_directions = []
|
29
|
+
processed_merge_commits = Set.new
|
30
|
+
|
31
|
+
head = repo.commits(branch).first
|
32
|
+
next_commit = head
|
33
|
+
finished = false
|
34
|
+
|
35
|
+
while(!finished)
|
36
|
+
current_commit = next_commit
|
37
|
+
print_story(current_commit, head, merge_commits, merge_commits_directions) if(current_commit.sha == searched_sha)
|
38
|
+
|
39
|
+
#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)
|
41
|
+
done = false
|
42
|
+
while(!done and merge_commits.any?)
|
43
|
+
merge_commits_directions[merge_commits_directions.length - 1] += 1
|
44
|
+
if(merge_commits_directions.last == merge_commits.last.parents.length)
|
45
|
+
processed_merge_commits << merge_commits.pop
|
46
|
+
merge_commits_directions.pop
|
47
|
+
else
|
48
|
+
done = true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
finished = merge_commits.empty?
|
52
|
+
next_commit = merge_commits.last.parents[merge_commits_directions.last] if !finished
|
53
|
+
|
54
|
+
#merge commit - update merge commits info and go to first parent of this merge commit
|
55
|
+
elsif(current_commit.parents.length > 1)
|
56
|
+
merge_commits << current_commit
|
57
|
+
merge_commits_directions << 0
|
58
|
+
next_commit = current_commit.parents[0]
|
59
|
+
|
60
|
+
#standard commit - go to first parent
|
61
|
+
else
|
62
|
+
next_commit = current_commit.parents[0]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
opts = Trollop::options do
|
68
|
+
opt :commit, "Specify a commit by its sha", :type => :string, :required => true
|
69
|
+
opt :branch, "Specify the branch that ended up containing the commit", :type => :string, :required => true
|
70
|
+
end
|
71
|
+
|
72
|
+
git_directory = `git rev-parse --show-toplevel`
|
73
|
+
repo = Grit::Repo.new(git_directory.chomp!)
|
74
|
+
|
75
|
+
if(repo.branches.index{|branch| branch.name.eql?(opts[:branch])}.nil?)
|
76
|
+
puts "Error: the specified branch does not exist."
|
77
|
+
exit(-1)
|
78
|
+
end
|
79
|
+
|
80
|
+
if(repo.commits(opts[:branch], false).index{|commit| commit.sha.eql?(opts[:commit])}.nil?)
|
81
|
+
puts "Error: the specified commit does not exist in the specified branch."
|
82
|
+
exit(-1)
|
83
|
+
end
|
84
|
+
|
85
|
+
story(opts[:commit], opts[:branch], repo)
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-story
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tom Van Eyck
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: grit
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: trollop
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: A Ruby script for git to find how a given commit made it into a particular
|
47
|
+
branch.
|
48
|
+
email: tomvaneyck@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- lib/git-story
|
54
|
+
homepage: https://github.com/vaneyckt/git-story
|
55
|
+
licenses: []
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.8.24
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: A Ruby script for git to find how a given commit made it into a particular
|
78
|
+
branch.
|
79
|
+
test_files: []
|