git-find-branching-point 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/git-find-branching-point +71 -0
- metadata +79 -0
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
require 'grit'
|
5
|
+
require 'trollop'
|
6
|
+
|
7
|
+
def describe(commit)
|
8
|
+
"#{commit.committed_date} #{commit.sha} #{commit.message.strip.split("\n").first} #{commit.committer}\n"
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_branches(repo)
|
12
|
+
branches = []
|
13
|
+
branches += repo.branches.map(&:name)
|
14
|
+
branches += repo.remotes.map(&:name)
|
15
|
+
branches.delete_if { |branch| branch == 'origin/HEAD' }
|
16
|
+
branches
|
17
|
+
end
|
18
|
+
|
19
|
+
def find_branching_point(repo, branch, branched_from)
|
20
|
+
branches = [branch, branched_from]
|
21
|
+
sha_to_branches = Hash.new { |h, k| h[k] = Set.new }
|
22
|
+
|
23
|
+
branches.each_with_index do |b, i|
|
24
|
+
puts "Indexing branch (#{i+1}/#{branches.length}): #{b}"
|
25
|
+
commit = repo.commits(b).first
|
26
|
+
while !commit.nil?
|
27
|
+
sha_to_branches[commit.sha] << b
|
28
|
+
commit = commit.parents.first
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
puts "Looking for branching point."
|
33
|
+
commit = repo.commits(branch).first
|
34
|
+
while !commit.nil? and !sha_to_branches[commit.sha].include?(branched_from)
|
35
|
+
commit = commit.parents.first
|
36
|
+
end
|
37
|
+
|
38
|
+
if !commit.nil?
|
39
|
+
puts "Found branching point."
|
40
|
+
puts describe(commit)
|
41
|
+
else
|
42
|
+
puts "No branching point was found."
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
opts = Trollop::options do
|
47
|
+
opt :branch, "Specify the branch you're interested in.", :type => :string
|
48
|
+
opt :branched_from, "Specify the branch that your branch of interest was branched from.", :type => :string
|
49
|
+
opt :show_branches, "Including this parameter will cause all available branches to be listed."
|
50
|
+
end
|
51
|
+
|
52
|
+
git_directory = `git rev-parse --show-toplevel`
|
53
|
+
repo = Grit::Repo.new(git_directory.chomp!)
|
54
|
+
|
55
|
+
branches = get_branches(repo)
|
56
|
+
if opts[:show_branches]
|
57
|
+
puts "Available branches: #{branches.join(', ')}"
|
58
|
+
exit(0)
|
59
|
+
end
|
60
|
+
|
61
|
+
if !opts[:branch].nil? and !branches.include?(opts[:branch])
|
62
|
+
puts "Error: the specified branch of interest does not exist. Remember that you can list all available branches with the --show-branches parameter."
|
63
|
+
exit(-1)
|
64
|
+
end
|
65
|
+
|
66
|
+
if !opts[:branched_from].nil? and !branches.include?(opts[:branched_from])
|
67
|
+
puts "Error: the specified branch that your branch of interest was branched from does not exist. Remember that you can list all available branches with the --show-branches parameter."
|
68
|
+
exit(-1)
|
69
|
+
end
|
70
|
+
|
71
|
+
find_branching_point(repo, opts[:branch], opts[:branched_from])
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git-find-branching-point
|
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-07-29 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 that helps you find the branching point between
|
47
|
+
two git branches.
|
48
|
+
email: tomvaneyck@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- lib/git-find-branching-point
|
54
|
+
homepage: https://github.com/vaneyckt/git-find-branching-point
|
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 that helps you find the branching point between two
|
78
|
+
git branches.
|
79
|
+
test_files: []
|