Sha256: 2ae3e3385062ed8fcb4ea9137c5db0e90b52e8fa283573546cbed4ecebc18754

Contents?: true

Size: 1.84 KB

Versions: 3

Compression:

Stored size: 1.84 KB

Contents

module GitBundle
  class Repository
    attr_reader :name,
                :path,
                :main

    def self.new_main(name, path)
      GitBundle::Repository.new(name, path, true, nil, nil)
    end

    def self.new_dependant(name, path, locked_branch, locked_revision)
      GitBundle::Repository.new(name, path, false, locked_branch, locked_revision)
    end

    def initialize(name, path, main_repository, locked_branch, locked_revision)
      @name = name
      @path = path
      @main = main_repository
      @locked_branch = locked_branch
      @locked_revision = locked_revision
    end

    def branch
      @branch ||= execute_git('rev-parse --abbrev-ref HEAD')
    end

    def locked_branch
      @locked_branch || branch
    end

    def revision
      @revision ||= execute_git('rev-parse --verify HEAD').gsub("\n", '')
    end

    def locked_revision
      @locked_revision || revision
    end

    def commits_not_pushed
      execute_git("log #{branch} --not --remotes")
    end

    def commit_messages_not_pushed
      count = execute_git("rev-list #{branch} --count --not --remotes").to_i
      count.times.map { |num| execute_git("log #{branch} --not --remotes --skip=#{num} --max-count=1 --pretty=format:'%B'").strip }
    end

    def push(args)
      puts execute_git("push #{args.join(' ')}")
      $?.exitstatus == 0
    end

    def file_changed?(filename)
      !execute_git("diff --name-only #{filename}").empty? && $?.exitstatus == 0
    end

    def add_file(filename)
      execute_git("add #{filename}")
      $?.exitstatus == 0
    end

    def commit(message, *files)
      execute_git("commit -m '#{message}' #{files.join(' ')}")
      $?.exitstatus == 0
    end

    def execute_git(command)
      full_command = "git -C #{@path} #{command}"
      puts full_command if ENV['DEBUG'] == 'true'
      `#{full_command}`.strip
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
git-bundle-1.0.4 lib/git_bundle/repository.rb
git-bundle-1.0.3 lib/git_bundle/repository.rb
git-bundle-1.0.2 lib/git_bundle/repository.rb