Sha256: 91bffa1722109a80959032bd2977521d4e2397ca965fa2e54b81ee2c17d64c3c

Contents?: true

Size: 762 Bytes

Versions: 1

Compression:

Stored size: 762 Bytes

Contents

require_relative "reporter"
require_relative "command"

module GitFonky
  class RepoDir
    attr_reader :command, :dirname, :reporter

    def initialize(dirname)
      @command = Command.new(self)
      @dirname = dirname
      @reporter = Reporter.new(self)
    end

    def branch
      @branch ||= command.current_branch
    end

    def sync
      Dir.chdir dirname do
        reporter.announce_update
        return reporter.invalid_branch_msg if on_invalid_branch?

        command.fetch_upstream
        command.pull_upstream

        return reporter.failed_pull_msg unless $?.success?

        command.push_to_origin
        reporter.announce_success
      end
    end

    def on_invalid_branch?
      !branch.match?(/(main|master)/)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git_fonky-0.3.0 lib/git_fonky/repo_dir.rb