class Cucumber::Pro::Scm::GitWorkingCopy

Public Class Methods

new(path) click to toggle source
# File lib/cucumber/pro/scm/working_copy.rb, line 27
def initialize(path)
  @path = path
end

Public Instance Methods

branch() click to toggle source

 tries to return the name of the origin branch that points to the current HEAD

# File lib/cucumber/pro/scm/working_copy.rb, line 40
def branch
  if remote_refs.empty?
    # just use local branch name
    return cmd("git name-rev --name-only HEAD")[0]
  end
  if remote_refs.length > 1
    fail "Multiple remote branches point to this commit: #{remote_refs.join(',')}"
  end
  remote_refs.first.gsub(/refs\/remotes\/\w+\//, '')
end
check_clean() click to toggle source
# File lib/cucumber/pro/scm/working_copy.rb, line 55
def check_clean
  check_no_modifications
  check_current_branch_pushed
end
repo_url() click to toggle source
# File lib/cucumber/pro/scm/working_copy.rb, line 31
def repo_url
  cmd('git ls-remote --get-url').each do |remote|
    return remote if remote =~ /(github|bitbucket)/
  end
  # Fallback if we didn't find one
  cmd('git config --get remote.origin.url').last
end
rev() click to toggle source
# File lib/cucumber/pro/scm/working_copy.rb, line 51
def rev
  cmd("git rev-parse HEAD").last
end

Private Instance Methods

check_current_branch_pushed() click to toggle source
# File lib/cucumber/pro/scm/working_copy.rb, line 82
def check_current_branch_pushed
  if cmd("git branch -r").any?
    # Only check if it's pushed if we actually have any remote branches
    # (which we do not for our tests)
    b = branch
    if cmd("git log origin/#{b}..#{b} --oneline").any?
      raise DirtyWorkingCopy.new("Your current branch has commits that haven't been pushed to origin. Please push your changes before running with the Cucumber Pro formatter.")
    end
  end
end
check_no_modifications() click to toggle source
# File lib/cucumber/pro/scm/working_copy.rb, line 76
def check_no_modifications
  if cmd("git status --untracked-files=no --porcelain").any?
    raise DirtyWorkingCopy.new("Please commit and push your changes before running with the Cucumber Pro formatter.")
  end
end
cmd(cmd) click to toggle source
# File lib/cucumber/pro/scm/working_copy.rb, line 72
def cmd(cmd)
  Dir.chdir(@path) { `#{cmd}` }.lines.map &:strip
end
refs() click to toggle source
# File lib/cucumber/pro/scm/working_copy.rb, line 68
def refs
  @refs ||= cmd("git show-ref | grep #{rev}").map { |output| output.split[1] }
end
remote_refs() click to toggle source
# File lib/cucumber/pro/scm/working_copy.rb, line 62
def remote_refs
  @remote_refs ||= refs.
    select { |ref| ref =~ /refs\/remotes/ }.
    reject { |ref| ref =~ /refs\/remotes\/\w+\/HEAD/ }
end