File: git.rake

package info (click to toggle)
jruby 1.5.6-9
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 45,088 kB
  • ctags: 77,093
  • sloc: ruby: 398,491; java: 170,202; yacc: 3,782; xml: 2,529; sh: 299; tcl: 40; makefile: 35; ansic: 23
file content (36 lines) | stat: -rw-r--r-- 1,095 bytes parent folder | download | duplicates (4)
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
def git_repo_exists?(dir)
  File.exists? File.join(dir, ".git")
end

def git_shallow_clone(label, git_repository, local_directory)
  git_clone(label, git_repository, local_directory, true)
end

def git_clone(label, git_repository, local_directory, shallow = false)
  puts "No #{label} repo found: cloning to #{local_directory}"
  rm_rf local_directory  # Something there, but not a git repo.  Destroy!
  cmd = "git clone #{git_repository} #{local_directory}"
  cmd << " --depth 1" if shallow
  sh cmd
  Dir.chdir(local_directory) { yield } if block_given?
end

def git_simple_command(command, label, local_directory)
  puts "#{label} repo found: `git #{command}` repo at #{local_directory}"
  Dir.chdir(local_directory) do 
    sh "git #{command}"
    yield if block_given?
  end 
end

def git_pull(label, local_directory)
  git_simple_command("pull", label, local_directory)
end

def git_fetch(label, local_directory)
  git_simple_command("fetch", label, local_directory)
end

def git_checkout(label, tag, local_directory)
  git_simple_command("checkout -q #{tag}", label, local_directory)
end