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
11
12
13
14
# File 'lib/routes/git_update.rb', line 5

def execute

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

    opts_validate
    opts_routing

end

#opts_routingObject



19
20
21
22
23
# File 'lib/routes/git_update.rb', line 19

def opts_routing

    update_branch_single

end

#opts_validateObject



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

def opts_validate
end

#update_branch_singleObject

Updates the current branch.

Returns:

  • void



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
57
58
59
60
61
62
63
64
65
# File 'lib/routes/git_update.rb', line 27

def update_branch_single
    release_error_code = false
    @git.check_for_uncommitted_files(true)
    @git.repo_loop.each do |repo_dir|
        current_branch = @git.current_branch_for_repo(repo_dir)

        # Skip if this is a release branch.
        if current_branch =~ App::Git::RELEASE_BRANCH_REGEX
            App::Terminal::warning("#{App::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))} is on a #{App::Terminal::format_highlight('release branch', true)}", ['Cannot perform update.'], release_error_code ? false : true)
            release_error_code = true
            next
        end

        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 --no-edit'
        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
            @git.check_for_conflicts(results[4], repo_dir, "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))}")
        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