Sha256: fb6f0c78084c4b710607b8032c1016a6fb32bad042a9869d9dba691ab74ff76a
Contents?: true
Size: 1.68 KB
Versions: 16
Compression:
Stored size: 1.68 KB
Contents
require 'dply/helper' module Dply module Git extend Helper def self.pull(branch) cmd "git fetch" checkout(branch) if tracking_branch = tracking_branch(branch) cmd "git merge #{tracking_branch}" else cmd "git pull origin #{branch}" end end def self.checkout(branch) current_branch = `git rev-parse --abbrev-ref HEAD `.chomp return if branch == current_branch local_branch_exists = system "git", "show-ref", "-q", "--verify", "refs/heads/#{branch}" if local_branch_exists cmd "git checkout #{branch} --" else cmd "git checkout -b #{branch} -t origin/#{branch}" end end def self.clone(repo, dir, mirror: nil) if mirror cmd "git clone #{mirror} #{dir}" Dir.chdir(dir) { cmd "git remote set-url origin #{repo}" } else cmd "git clone #{repo} #{dir}" end end def self.clean cmd "git reset --hard HEAD" cmd "git clean -dxf " end def self.tracking_branch(branch) command = "git for-each-ref --format='%(upstream:short)' refs/heads/#{branch} --count=1" tracking_branch = cmd command, return_output: true, display: false if tracking_branch =~ /[a-zA-Z0-9_]/ return tracking_branch.chomp! else return nil end end def self.remote_url remote_url = cmd "git config --get remote.origin.url", return_output: true, display: false logger.debug remote_url.chomp remote_url.chomp end def self.commit_id commit_id = cmd "git rev-parse HEAD", return_output: true, display: false logger.debug commit_id.chomp commit_id.chomp end end end
Version data entries
16 entries across 16 versions & 1 rubygems