-
Notifications
You must be signed in to change notification settings - Fork 0
/
git.rb
41 lines (30 loc) · 877 Bytes
/
git.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module GithubBackup
class Git
attr_accessor :repository
attr_writer :target_dir
# Takes a target_dir string and a Repository class
def initialize(target_dir, repository)
self.target_dir = target_dir
raise "GitHub backup directory, #{self.target_dir}, does not exist!" unless File.directory?(self.target_dir)
self.repository = repository
end
def create_mirror
`#{go_to_target_dir} && git clone --mirror #{repository.ssh_url} #{mirror_directory}`
end
def go_to_target_dir
"cd #{target_dir}"
end
def mirror_directory
"#{repository.name}.git"
end
def mirror_exists?
Dir.exists? File.join(target_dir, "#{mirror_directory}")
end
def target_dir
File.expand_path(@target_dir)
end
def update_mirror
`#{go_to_target_dir} && git fetch`
end
end
end