Class: AssistedWorkflow::Addons::Git

Inherits:
Base
  • Object
show all
Defined in:
lib/assisted_workflow/addons/git.rb

Constant Summary collapse

DESCRIPTION_LIMIT =
30

Instance Method Summary collapse

Methods inherited from Base

get_required_options, #name, required_options, #valid?

Constructor Details

#initialize(output, options = {}) ⇒ Git

Returns a new instance of Git.



12
13
14
15
# File 'lib/assisted_workflow/addons/git.rb', line 12

def initialize(output, options = {})
  super
  @command_options = {:raise_error => true}.merge(options)
end

Instance Method Details

#check_merged!Object

check if current branch is merged into master



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/assisted_workflow/addons/git.rb', line 57

def check_merged!
  check_everything_commited!
  branch = current_branch
  git "checkout master"
  git "pull --rebase"
  merged = git("branch --merged").include?(branch)
  git "checkout #{branch}"
  unless merged
    raise AssistedWorkflow::Error, "this branch is not merged into master"
  end
  merged
end

#create_story_branch(story) ⇒ Object

creates a new git branch based on story attributes the branch name format is:

> story_onwer_username.story_id.story_name



20
21
22
23
24
25
# File 'lib/assisted_workflow/addons/git.rb', line 20

def create_story_branch(story)
  log "creating the feature branch"
  branch = branch_name(story)
  git "checkout -b #{branch}"
  # git "push --set-upstream origin #{branch}"
end

#current_branchObject

returns the current local branch name



45
46
47
# File 'lib/assisted_workflow/addons/git.rb', line 45

def current_branch
  git("rev-parse --abbrev-ref HEAD", :silent => true)
end

#current_story_idObject

returns the current story id based on branch name



40
41
42
# File 'lib/assisted_workflow/addons/git.rb', line 40

def current_story_id
  current_branch.split(".")[1]
end

#rebase_and_pushObject

run all the git steps required for a clean pull request



28
29
30
31
32
33
34
35
36
37
# File 'lib/assisted_workflow/addons/git.rb', line 28

def rebase_and_push
  log "preparing local branch"
  check_everything_commited!
  branch = current_branch
  git "checkout master"
  git "pull --rebase"
  git "checkout #{branch}"
  git "rebase master"
  git "push -u -f origin #{branch}"
end

#remove_branchObject

removes current branch and its remote version



71
72
73
74
75
76
77
# File 'lib/assisted_workflow/addons/git.rb', line 71

def remove_branch
  log "removing local and remote feature branches"
  branch = current_branch
  git "push origin :#{branch}", :raise_error => false
  git "checkout master"
  git "branch -D #{branch}"
end

#repositoryObject

returns the repository name assigned to origin following the format: owner/project



51
52
53
54
# File 'lib/assisted_workflow/addons/git.rb', line 51

def repository
  url = git("config --get remote.origin.url", :error => "cannot find 'origin' remote repository url")
  url.gsub("[email protected]:", "").gsub("https://github.com/", "").gsub(/\.git$/, "").chomp
end