Class: AppCommand::GitPush

Inherits:
Convoy::ActionCommand::Base
  • Object
show all
Defined in:
lib/routes/git_push.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/routes/git_push.rb', line 5

def execute

    @opts = command_options
    @args = arguments
    @git = App::Git.new

    opts_validate
    opts_routing

end

#git_pushObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/routes/git_push.rb', line 30

def git_push

    @git.check_for_same_branch(App::Git::SAME_BRANCH_WARNING)
    branch_code = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
    branch_db = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB))

    branches_to_push = []
    branches_to_push << "#{App::Terminal::format_directory(@git.get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)))} will push #{App::Terminal::format_branch(branch_code)} \xe2\x86\x92 #{App::Terminal::format_branch("origin/#{branch_code}")}" unless branch_code == App::Git::MASTER
    branches_to_push << "#{App::Terminal::format_directory(@git.get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)))}   will push #{App::Terminal::format_branch(branch_db)} \xe2\x86\x92 #{App::Terminal::format_branch("origin/#{branch_db}")}" unless branch_db == App::Git::MASTER

    unless branches_to_push.any?
        App::Terminal::error("#{App::Terminal::format_action('pushing')} to #{App::Terminal::format_branch(App::Git::MASTER)} is best done manually.", nil, true)
    end

    if App::Terminal::prompt_yes_no("#{App::Terminal::format_action('push')} the following repos:", branches_to_push)
        @git.check_for_uncommitted_files(true)
        @git.repo_loop.each do |repo_dir|
            current_branch = @git.current_branch_for_repo(repo_dir)
            if current_branch != App::Git::MASTER
                unless App::Terminal::command_capture("git push origin #{current_branch}", repo_dir)
                    App::Terminal::warning('Something went wrong', "Not sure what the reason was, but doing a #{App::Terminal::format_command('git push')} on #{App::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))} was unsuccessful.")
                end
            end
        end
        @git.check_for_stash(true)
    end

end

#opts_routingObject



24
25
26
27
28
# File 'lib/routes/git_push.rb', line 24

def opts_routing

    git_push

end

#opts_validateObject



16
17
18
19
20
21
22
# File 'lib/routes/git_push.rb', line 16

def opts_validate

    if @args[0].nil?
        @args[0] = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
    end

end