Class: Toothpick::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/toothpick/git.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(git_dir) ⇒ Git

Returns a new instance of Git.



14
15
16
# File 'lib/toothpick/git.rb', line 14

def initialize(git_dir)
  @git_dir = git_dir
end

Instance Attribute Details

#git_dirObject (readonly)

Returns the value of attribute git_dir.



4
5
6
# File 'lib/toothpick/git.rb', line 4

def git_dir
  @git_dir
end

Class Method Details

.clone_repo(repo, target_dir) ⇒ Object



6
7
8
# File 'lib/toothpick/git.rb', line 6

def self.clone_repo(repo, target_dir)
  system("git clone #{repo} #{target_dir}")
end

.on_git?(dir) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/toothpick/git.rb', line 10

def self.on_git?(dir)
  return system("cd #{dir} && git rev-parse --git-dir")
end

Instance Method Details

#commitObject



22
23
24
25
26
# File 'lib/toothpick/git.rb', line 22

def commit
  system("cd #{git_dir} "\
    "&& git add --all "\
    "&& git commit -m '#{make_commit_message}'")
end

#make_commit_messageObject



28
29
30
# File 'lib/toothpick/git.rb', line 28

def make_commit_message
  "Added pick by #{ENV['USER']} on #{Time.now}"
end

#pushObject



32
33
34
# File 'lib/toothpick/git.rb', line 32

def push
  system("cd #{git_dir} && git push origin master")
end

#updateObject



18
19
20
# File 'lib/toothpick/git.rb', line 18

def update
  system("cd #{git_dir} && git pull --rebase")
end