Class: GitCommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/travis_github_deployer/git_command_line.rb

Instance Method Summary collapse

Instance Method Details

#add(filename) ⇒ Object



13
14
15
# File 'lib/travis_github_deployer/git_command_line.rb', line 13

def add(filename)
  git("add #{filename}")
end

#clone(repository, destination) ⇒ Object



5
6
7
# File 'lib/travis_github_deployer/git_command_line.rb', line 5

def clone(repository, destination)
  git("clone " + repository + " " + destination)
end

#commit(message) ⇒ Object



17
18
19
# File 'lib/travis_github_deployer/git_command_line.rb', line 17

def commit(message)
  git("commit -m \"#{message}\"")
end

#config(key, value) ⇒ Object



9
10
11
# File 'lib/travis_github_deployer/git_command_line.rb', line 9

def config(key, value)
  git("config #{key} '#{value}'")
end

#config_credential_helper_store_file(filename) ⇒ Object



44
45
46
# File 'lib/travis_github_deployer/git_command_line.rb', line 44

def config_credential_helper_store_file(filename)
  config("credential.helper", "store --file=#{filename}")
end

#config_email(email) ⇒ Object



40
41
42
# File 'lib/travis_github_deployer/git_command_line.rb', line 40

def config_email(email)
  config("user.email", email)
end

#config_username(username) ⇒ Object



36
37
38
# File 'lib/travis_github_deployer/git_command_line.rb', line 36

def config_username(username)
  config("user.name", username)
end

#do_system(command) ⇒ Object



65
66
67
# File 'lib/travis_github_deployer/git_command_line.rb', line 65

def do_system(command)
  `#{command}`
end

#filter_branch(patterns) ⇒ Object



21
22
23
24
25
26
# File 'lib/travis_github_deployer/git_command_line.rb', line 21

def filter_branch(patterns)
  git("filter-branch --force --index-filter " +
      "'git rm --cached --ignore-unmatch #{patterns}' " +
      "--prune-empty --tag-name-filter cat -- --all"
  )
end

#force_pushObject



28
29
30
# File 'lib/travis_github_deployer/git_command_line.rb', line 28

def force_push
  git("push -f")
end

#git(command) ⇒ Object

Raises:

  • (StandardError)


56
57
58
59
60
61
62
63
# File 'lib/travis_github_deployer/git_command_line.rb', line 56

def git(command)
  git_command = "git #{command}"
  puts("command: #{git_command}") if verbose
  output = do_system("#{git_command} 2>&1")
  puts("output: #{output}") if verbose
  raise StandardError, "Git command: '#{command}' failed. Message: : " + output unless previous_command_success
  output
end

#previous_command_successObject



69
70
71
# File 'lib/travis_github_deployer/git_command_line.rb', line 69

def previous_command_success
  $?.success?
end

#pushObject



32
33
34
# File 'lib/travis_github_deployer/git_command_line.rb', line 32

def push
  git("push")
end

#verboseObject



52
53
54
# File 'lib/travis_github_deployer/git_command_line.rb', line 52

def verbose
  @verbose
end

#verbose=(value) ⇒ Object



48
49
50
# File 'lib/travis_github_deployer/git_command_line.rb', line 48

def verbose=(value)
  @verbose = true
end