Class: Git::Daily::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/git-daily/command.rb

Direct Known Subclasses

Config, Help, Init, Pull, Push, Release, Version

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommand

Returns a new instance of Command.



6
7
# File 'lib/git-daily/command.rb', line 6

def initialize
end

Class Method Details

.branchesObject



25
26
27
28
# File 'lib/git-daily/command.rb', line 25

def self.branches
  r = `git branch --no-color`.split(/\n/)
  r.map! { |b| b[/^\*/] ? b[2 .. -1] : b.strip }
end

.clean?Boolean

Returns:

  • (Boolean)


100
101
102
103
# File 'lib/git-daily/command.rb', line 100

def self.clean?
  r = `git status -uno -s`.split(/\n/)
  r.empty? ? true : false
end

.current_branchObject



79
80
81
82
83
84
# File 'lib/git-daily/command.rb', line 79

def self.current_branch
  r = `git branch --no-color`.split(/\n/)
  master = r.select { |v| v[/^\*/] }
  return nil if master.empty?
  master[0][/^\* (.*)/, 1]
end

.developObject



47
48
49
50
51
# File 'lib/git-daily/command.rb', line 47

def self.develop
  r = `git config gitdaily.develop`
  r.chomp!
  r.empty? ? nil : r
end

.has_branch?(branch) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/git-daily/command.rb', line 30

def self.has_branch?(branch)
  r = branches
  r.find {|i| i == branch } ? true : false
end

.has_remote_branch?(remote, branch) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
95
96
97
98
# File 'lib/git-daily/command.rb', line 92

def self.has_remote_branch?(remote, branch)
  if remote_branch(remote, branch)
    true
  else
    false
  end
end

.logurlObject



53
54
55
56
57
# File 'lib/git-daily/command.rb', line 53

def self.logurl
  r = `git config gitdaily.logurl`
  r.chomp!
  r.empty? ? nil : r
end

.masterObject



41
42
43
44
45
# File 'lib/git-daily/command.rb', line 41

def self.master
  r = `git config gitdaily.master`
  r.chomp!
  r.empty? ? nil : r
end

.merged_branchesObject



110
111
112
113
# File 'lib/git-daily/command.rb', line 110

def self.merged_branches
  r = `git branch --no-color --merged`.split(/\n/)
  r.map! { |b| b[/^\*/] ? b[2 .. -1] : b.strip }
end

.pull_request_urlObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/git-daily/command.rb', line 59

def self.pull_request_url
  r = `git config gitdaily.pullRequestUrl`
  r.chomp!

  return r unless r.empty?

  remote = self.remote
  if remote
    url_format = "https://github.com/%s/%s/pull/%s"
    github = `git config remote.#{remote}.url`
    github.chomp!

    github.match(/^git@github\.com:(?<org>.+)\/(?<repo>.+)\.git$/) do |match|
      r = sprintf(url_format, match[:org], match[:repo], "%d")
    end
  end

  r.empty? ? nil : r
end

.release_branches(branch) ⇒ Object



105
106
107
108
# File 'lib/git-daily/command.rb', line 105

def self.release_branches(branch)
  r = `git branch --no-color`.split(/\n/).select { |a| a[/#{branch}/] }
  r.map! { |b| b[/^\*/] ? b[2 .. -1] : b.strip }
end

.remoteObject



35
36
37
38
39
# File 'lib/git-daily/command.rb', line 35

def self.remote
  r = `git config gitdaily.remote`
  r.chomp!
  r.empty? ? nil : r
end

.remote_branch(remote, current_branch) ⇒ Object



86
87
88
89
90
# File 'lib/git-daily/command.rb', line 86

def self.remote_branch(remote, current_branch)
  r = `git branch --no-color -a`.split(/\n/).select { |a| a[/remotes\/#{remote}\/#{current_branch}/] }
  return nil if r.empty?
  r[0].strip
end

.remotesObject



21
22
23
# File 'lib/git-daily/command.rb', line 21

def self.remotes
  `git config --list --no-color`.split(/\n/).select {|a| a[/^remote\.([^\.]+)\.url/] }
end

Instance Method Details

#helpObject

Raises:

  • (NotImplementedError)


13
14
15
# File 'lib/git-daily/command.rb', line 13

def help
  raise NotImplementedError.new("You most implement help.")
end

#runObject

Raises:

  • (NotImplementedError)


9
10
11
# File 'lib/git-daily/command.rb', line 9

def run
  raise NotImplementedError.new("You most implement run.")
end