Class: CreateGithubRelease::Assertions::LocalAndRemoteOnSameCommit

Inherits:
CreateGithubRelease::AssertionBase show all
Defined in:
lib/create_github_release/assertions/local_and_remote_on_same_commit.rb

Overview

Assert that the local working directory and the remote are on the same commit

Checks both the local repository and the remote repository.

Instance Attribute Summary

Attributes inherited from CreateGithubRelease::AssertionBase

#project

Instance Method Summary collapse

Methods inherited from CreateGithubRelease::AssertionBase

#backtick_debug?, #error, #initialize, #print, #puts

Methods included from BacktickDebug

#`

Constructor Details

This class inherits a constructor from CreateGithubRelease::AssertionBase

Instance Method Details

#assert

This method returns an undefined value.

Make sure that the local working directory and the remote are on the same commit

Examples:

require 'create_github_release'

options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'major' }
project = CreateGithubRelease::Project.new(options)
assertion = CreateGithubRelease::Assertions::LocalAndRemoteOnSameCommit.new(project)
begin
  assertion.assert
  puts 'Assertion passed'
rescue SystemExit
  puts 'Assertion failed'
end

Raises:

  • (SystemExit)

    if the assertion fails



34
35
36
37
38
39
40
41
42
43
# File 'lib/create_github_release/assertions/local_and_remote_on_same_commit.rb', line 34

def assert
  print 'Checking that local and remote are on the same commit...'
  local_commit = `git rev-parse HEAD`.chomp
  remote_commit = `git ls-remote '#{project.remote}' '#{project.default_branch}' | cut -f 1`.chomp
  if local_commit == remote_commit
    puts 'OK'
  else
    error 'Local and remote are not on the same commit'
  end
end