Class: Xcodeci::GitUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/xcodeci/gitutils.rb

Instance Method Summary collapse

Instance Method Details

#checkout_repo(branch) ⇒ Object



26
27
28
29
# File 'lib/xcodeci/gitutils.rb', line 26

def checkout_repo branch 
  %x(git checkout #{branch} 2>&1)
  $?.exitstatus.zero?
end

#cloning_repo(repository_url) ⇒ Object

def execute_in_repo_folder (repository_url, &block)

Dir.chdir "#{Xcodeci::HOME}/#{repository_name repository_url}"
result = block.call
Dir.chdir "#{Xcodeci::HOME}"
result

end



14
15
16
17
18
19
# File 'lib/xcodeci/gitutils.rb', line 14

def cloning_repo repository_url
  #Cloning the repository, it fails if the repository is already cloned
  dest_folder = File.join(Xcodeci::HOME, (repository_name repository_url))
  clone_result = %x(git clone #{repository_url} #{dest_folder} 2>&1)
  $?.exitstatus.zero?
end

#fetch_repoObject



21
22
23
24
# File 'lib/xcodeci/gitutils.rb', line 21

def fetch_repo
  %x(git fetch 2>&1)
  $?.exitstatus.zero?
end

#get_commit_listsObject



36
37
38
39
40
# File 'lib/xcodeci/gitutils.rb', line 36

def get_commit_lists      
  last_commit = %x(git log  -10 --date-order --pretty=format:"%h %ce").split(/\n/)
  # a single line shoud be in this format  "e2d4a86 ignaziocgmail.com"
  last_commit
end

#pull_repoObject



31
32
33
34
# File 'lib/xcodeci/gitutils.rb', line 31

def pull_repo      
  %x(git pull 2>&1)
  $?.exitstatus.zero?
end

#repository_name(repo_url) ⇒ Object



4
5
6
# File 'lib/xcodeci/gitutils.rb', line 4

def repository_name repo_url
  repo_url[repo_url.rindex('/') + 1..-1].sub('.git', '')
end

#rollback_repo(commit) ⇒ Object



42
43
44
45
# File 'lib/xcodeci/gitutils.rb', line 42

def rollback_repo commit
    %x(git checkout "#{commit}" 2>&1)
    $?.exitstatus.zero?
end