Class: AppCommand::GitUpdate

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

Instance Method Summary collapse

Instance Method Details

#executeObject



5
6
7
8
9
10
# File 'lib/routes/git_update.rb', line 5

def execute
    @git = App::Git.new
    @opts = command_options
    opts_validate
    opts_routing
end

#opts_routingObject



15
16
17
18
19
# File 'lib/routes/git_update.rb', line 15

def opts_routing

    update_branch_single

end

#opts_validateObject



12
13
# File 'lib/routes/git_update.rb', line 12

def opts_validate
end

#update_branch_singleObject

Updates the current branch.

Returns:

  • void



23
24
25
26
27
28
29
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
# File 'lib/routes/git_update.rb', line 23

def update_branch_single
    @git.check_for_uncommitted_files(true)
    @git.repo_loop.each do |repo_dir|
        current_branch = @git.current_branch_for_repo(repo_dir)
        commands = Array.new
        if current_branch != App::Git::MASTER
            commands << "git checkout #{App::Git::MASTER}"
        end
        commands << "git pull origin #{App::Git::MASTER}"
        if current_branch != App::Git::MASTER
            commands << "git checkout #{current_branch}"
            commands << "git pull origin #{current_branch}"
            commands << 'git merge master'
        end
        results = App::Terminal::command(commands, repo_dir)
        if current_branch != App::Git::MASTER
            if results[3] == false
                @git.ask_to_setup_remote_tracking(current_branch, repo_dir)
            end
            if results[4] == false
                unless App::Terminal::prompt_yes_no('Merge conflict occurred', ["Unable to successfully merge #{App::Terminal::format_branch(App::Git::MASTER)} into #{App::Terminal::format_branch(current_branch)} on #{App::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))}", "Please #{App::Terminal::format_action('open an IDE')}\x1B[38;5;240m and resolve your conflicts as soon as this script has finished executing."])
                    App::Terminal::abort(nil, nil, true, false)
                end
            end
        end
        if @opts[:push] && current_branch != App::Git::MASTER
            App::Terminal::command("git push origin #{current_branch}", repo_dir)
        elsif @opts[:push] && current_branch == App::Git::MASTER
            App::Terminal::warning("#{App::Terminal::format_action('push')} to #{App::Terminal::format_branch(App::Git::MASTER)} not allowed!", ["Your #{App::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))} repo is currently on #{App::Terminal::format_branch(App::Git::MASTER)}", "The script will not perform a #{App::Terminal::format_action('push')} as requested for safety reasons."])
        end

    end
    @git.check_for_stash(true)
end