Sha256: ac194f5df99d08f4c2bfe3e631efa81fa689b951dbcaec6025dfa445bdc68dd4

Contents?: true

Size: 1.3 KB

Versions: 15

Compression:

Stored size: 1.3 KB

Contents

require 'dply/shell'
module Dply
  module Git

    extend Shell

    def self.pull(branch)
      cmd "git fetch"
      checkout(branch)
      if tracking_branch = get_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.to_sym
      cmd "git checkout #{branch}" if branch != current_branch
    end

    def self.clone(repo, dir, mirror: nil)
      cmd "git clone #{repo} #{dir}"
    end

    def self.clean
      cmd "git reset --hard HEAD"
      cmd "git clean -dxf "
    end

    def self.get_tracking_branch(branch)
      command = "git for-each-ref --format='%(upstream:short)' refs/heads/#{branch} --count=1"
      tracking_branch = `#{command}`
      if tracking_branch =~ /[a-zA-Z0-9_]/
        return tracking_branch.chomp!
      else
        return nil
      end  
    end

    def self.get_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

15 entries across 15 versions & 1 rubygems

Version Path
dply-0.1.13 lib/dply/git.rb
dply-0.1.12 lib/dply/git.rb
dply-0.1.11 lib/dply/git.rb
dply-0.1.10 lib/dply/git.rb
dply-0.1.9 lib/dply/git.rb
dply-0.1.8 lib/dply/git.rb
dply-0.1.7 lib/dply/git.rb
dply-0.1.6 lib/dply/git.rb
dply-0.1.5 lib/dply/git.rb
dply-0.1.4 lib/dply/git.rb
dply-0.1.2 lib/dply/git.rb
dply-0.1.1 lib/dply/git.rb
dply-0.1.0 lib/dply/git.rb
dply-0.0.8 lib/dply/git.rb
dply-0.0.7 lib/dply/git.rb