Class: GitIt::Commander

Inherits:
Object
  • Object
show all
Defined in:
lib/git-it/commander.rb

Overview

Grand central station for git it commands

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Commander

global options
–help

Show this message

-p, –path=path

repository path (default: {present_working_directory})

-s, –sha=sha

SHA1 (default: {current_head})

sample usage

Open present working directory’s repository branch:

git it opened

Open specified repository in the path:

git it --path=the/path/to/the/repo opened

Open specified sha1:

git it --sha=50m35ha1 opened

Open specified repository in the path and sha1:

git it --path=the/path/to/the/repo --sha=50m35ha1 opened


34
35
36
37
38
39
40
41
# File 'lib/git-it/commander.rb', line 34

def initialize(options)
  @global_options = options
  @repository     = Rugged::Repository.new( get_path(options[:path]) )
  @git_object     = get_object( options[:sha] )
  @test_mode      = options[:test]

  @url_generator = UrlGenerator.new( @repository.config["remote.origin.url"] )
end

Instance Attribute Details

#git_objectObject (readonly)

current git object



12
13
14
# File 'lib/git-it/commander.rb', line 12

def git_object
  @git_object
end

#repositoryObject (readonly)

current git repository



9
10
11
# File 'lib/git-it/commander.rb', line 9

def repository
  @repository
end

Instance Method Details

#compare(args, options) ⇒ Object

get it compared

Compares the current branch to another branch (default: master)

sample usage

Compare the current branch to master branch

git it compared

Compare the current branch to release branch

git it compared --to=release


83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/git-it/commander.rb', line 83

def compare(args, options)
  _closest_branch = closest_branch

  if _closest_branch
    branch_name = clean_branch_name_for( _closest_branch )
    link        = @url_generator.compare_branches_url( branch_name, options[:to] || "master" )

    launch link
  else
    fail "Could not find closest remote branch for sha: #{@git_object.oid.inspect}"
  end
end

#open(args, options) ⇒ Object

get it opened

Opens the current branch

sample usage

Open the current branch:

git it opened


58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/git-it/commander.rb', line 58

def open(args, options)
  _closest_branch = closest_branch

  if _closest_branch
    branch_name = clean_branch_name_for( _closest_branch )
    link        = @url_generator.branch_url( branch_name )

    launch link
  else
    fail "Could not find closest remote branch for sha: #{@git_object.oid.inspect}"
  end
end

#pull(args, options) ⇒ Object

get it pulled

Issues a pull request of the current branch into another branch (default: master)

sample usage

Issue a pull request of the current branch into master branch

git it pulled

Issue a pull request of the current branch into release branch

git it pulled --to=release


108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/git-it/commander.rb', line 108

def pull(args, options)
  _closest_branch = closest_branch

  if _closest_branch
    branch_name = clean_branch_name_for( _closest_branch )
    link        = @url_generator.pull_request_url( branch_name, options[:to] || "master" )

    launch link
  else
    fail "Could not find closest remote branch for sha: #{@git_object.oid.inspect}"
  end
end

#test(args, options) ⇒ Object

get it opened

Opens the current branch

sample usage

Open the current branch:

git it opened


130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/git-it/commander.rb', line 130

def test(args, options)
  _closest_branch = closest_branch

  if _closest_branch
    branch_name = clean_branch_name_for( _closest_branch )
    link        = @url_generator.test_url( branch_name )

    launch link
  else
    fail "Could not find closest remote branch for sha: #{@git_object.oid.inspect}"
  end
end