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
42
|
# File 'lib/fido.rb', line 10
def clone(repo, *to)
force = to.last == true && to.pop
to << "master"
dir = File.basename(repo, ".git")
mkdir_p dir
cd dir do
return if !force && File.exists?(".git/FIDO")
if !File.exists?(".git")
cmd "git init"
cmd "git remote add origin #{repo}"
end
cmd "git fetch origin"
branches = cmd("git branch -a")
to.each do |branch|
if branches =~ /\* #{branch}\n/
cmd "git reset --hard origin/#{branch}"
break
elsif branches =~ / remotes\/origin\/#{branch}\n/
cmd "git branch -D #{branch}" if branches =~ / #{branch}\n/
cmd "git checkout -b #{branch} origin/#{branch}"
break
end
end
touch ".git/FIDO"
end
end
|