Class: Versi::Interfaces::GitInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/versi/interfaces/git_interface.rb

Constant Summary collapse

DEFAULT_REMOTE =
"origin"
GIT_TAG_LIST_COMMAND =
"git tag --list"
GIT_FETCH_TAGS_COMMAND =
"git fetch --tags"
GIT_LAST_COMMIT_MSG_COMMAND =
"git log -1 --pretty=%B"

Instance Method Summary collapse

Constructor Details

#initialize(remote: DEFAULT_REMOTE) ⇒ GitInterface

Returns a new instance of GitInterface.



11
12
13
14
# File 'lib/versi/interfaces/git_interface.rb', line 11

def initialize(remote: DEFAULT_REMOTE)
  remote ||= DEFAULT_REMOTE
  @remote = remote
end

Instance Method Details

#create_branch(branch_name) ⇒ Object



50
51
52
53
# File 'lib/versi/interfaces/git_interface.rb', line 50

def create_branch(branch_name)
  Versi::LOG.info("Creating branch #{branch_name}.. ")
  System.call!("git checkout -b #{branch_name}")
end

#create_tag(tag, message = nil) ⇒ Object



16
17
18
19
# File 'lib/versi/interfaces/git_interface.rb', line 16

def create_tag(tag, message=nil)
  Versi::LOG.info("Generating git tag \"#{tag}\".. ")
  System.call!("git tag -a \"#{tag}\" -m \"#{message}\"")
end

#delete_tag(tag) ⇒ Object



21
22
23
24
# File 'lib/versi/interfaces/git_interface.rb', line 21

def delete_tag(tag)
  Versi::LOG.info("Deleting git tag \"#{tag}\".. ")
  System.call!("git tag -d \"#{tag}\"")
end

#delete_tag_remote(tag) ⇒ Object



26
27
28
29
# File 'lib/versi/interfaces/git_interface.rb', line 26

def delete_tag_remote(tag)
  Versi::LOG.info("Deleting git tag \"#{tag}\" on remote (#{@remote}).. ")
  System.call!("git push #{@remote} --delete \"#{tag}\"")
end

#fetch_tagsObject



36
37
38
39
# File 'lib/versi/interfaces/git_interface.rb', line 36

def fetch_tags
  Versi::LOG.info("Updating local git tags.. ")
  System.call!(GIT_FETCH_TAGS_COMMAND)
end

#last_commit_messageObject



46
47
48
# File 'lib/versi/interfaces/git_interface.rb', line 46

def last_commit_message
  System.call!(GIT_LAST_COMMIT_MSG_COMMAND).stdout.join("\n")
end

#list_tagsObject



41
42
43
44
# File 'lib/versi/interfaces/git_interface.rb', line 41

def list_tags
  response = System.call!(GIT_TAG_LIST_COMMAND)
  response.stdout
end

#push_tag(tag) ⇒ Object



31
32
33
34
# File 'lib/versi/interfaces/git_interface.rb', line 31

def push_tag(tag)
  Versi::LOG.info("Pushing \"#{tag}\" git tag.. ")
  System.call!("git push #{@remote} #{tag}")
end