git-switcher 0.0.2 → 1.0.0

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.
@@ -1,93 +0,0 @@
1
- require 'rugged'
2
-
3
- class Git::Switcher::Repo < Rugged::Repository
4
-
5
- def repo
6
- # a bug/feature in Rugged prevents us from using instances of a subclass of Rugged::Repository
7
- # in certain methods/places; instead it insists on an instance of Rugged::Repository itself...
8
- # (meaning we can't use `self` on those occasions!) where is Barbara Liskov when you need her?
9
- @repo ||= Rugged::Repository.new(self.path)
10
- end
11
-
12
- def current_branch
13
- Rugged::Reference.lookup(self, 'HEAD').target.scan(/\Arefs\/heads\/(.*)\Z/).flatten.first
14
- end
15
-
16
- def current_head? ref
17
- target('HEAD') == target(ref)
18
- end
19
-
20
- def reachable? ref
21
- self.class.reachable? target('HEAD'), target(ref)
22
- end
23
-
24
- def abbreviated_name ref
25
- ref.gsub(/\Arefs\/(remotes|heads|tags)\//, '')
26
- end
27
-
28
- # remote branches
29
-
30
- def remote_branches
31
- self.refs.find_all { |ref| ref =~ /\Arefs\/remotes\// && ref !~ /\/HEAD\Z/ }
32
- end
33
-
34
- def remote_branch_name ref
35
- ref.gsub(/\Arefs\/remotes\//, '')
36
- end
37
-
38
- def remote_branch_names
39
- remote_branches.map { |ref| remote_branch_name(ref) }
40
- end
41
-
42
- # local branches
43
-
44
- def local_branches
45
- self.refs.find_all { |ref| ref =~ /\Arefs\/heads\// }
46
- end
47
-
48
- def local_branch_name ref
49
- ref.gsub(/\Arefs\/heads\//, '')
50
- end
51
-
52
- def local_branch_names
53
- local_branches.map { |ref| local_branch_name(ref) }
54
- end
55
-
56
- # tags
57
-
58
- def tags
59
- self.refs.find_all { |ref| ref =~ /\Arefs\/tags\// }
60
- end
61
-
62
- def reachable_tags # time-ordered, as well
63
- tags.find_all { |tag| reachable? tag }.sort { |first_tag, second_tag|
64
- # use 'author' timestamp, not 'committer' timestamp, e.g. in case
65
- # the tag's target commit was the result of a rebase operation!!!
66
- target(first_tag).author[:time] <=> target(second_tag).author[:time]
67
- }
68
- end
69
-
70
- def tag_name ref
71
- ref.gsub(/\Arefs\/tags\//, '')
72
- end
73
-
74
- def tag_names
75
- tags.map { |ref| tag_name(ref) }
76
- end
77
-
78
- private
79
-
80
- def target ref
81
- # TODO read up on git tagging, ie. tag another tag, ad infinitum (?)
82
- target = self.repo.lookup(Rugged::Reference.lookup(self, ref).resolve.target)
83
- target = target.target if target.is_a? Rugged::Tag
84
- target
85
- end
86
-
87
- def self.reachable? current_commit, past_commit
88
- (current_commit == past_commit) || begin
89
- current_commit.parents.any? { |parent| self.reachable? parent, past_commit }
90
- end
91
- end
92
-
93
- end
@@ -1,5 +0,0 @@
1
- module Git
2
- module Switcher
3
- VERSION = "0.0.2"
4
- end
5
- end
data/lib/git-switcher.rb DELETED
@@ -1,17 +0,0 @@
1
- require 'rubygems'
2
-
3
- require 'rugged'
4
- require 'trollop'
5
-
6
- require 'git-switcher/version'
7
- require 'git-switcher/banner'
8
- require 'git-switcher/copyright'
9
-
10
- require 'git-switcher/repo'
11
- require 'git-switcher/menu'
12
-
13
- module Git
14
- module Switcher
15
- # Your code goes here...
16
- end
17
- end
@@ -1,9 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Git::Switcher::Repo do
4
-
5
- it "subclasses Rugged::Repository" do
6
- described_class.superclass.should be Rugged::Repository
7
- end
8
-
9
- end
@@ -1,7 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Git::Switcher do
4
- it "is a module" do
5
- Git::Switcher.should be_instance_of(Module)
6
- end
7
- end
data/spec/spec_helper.rb DELETED
@@ -1,8 +0,0 @@
1
- $:.unshift File.realpath File.join(File.dirname(__FILE__), '..', 'lib')
2
-
3
- require 'git-switcher'
4
-
5
- require 'rspec/pride'
6
-
7
- require 'pry'
8
- require 'awesome_print'