Class: App::GitDelete

Inherits:
Object
  • Object
show all
Defined in:
lib/core/git_delete.rb

Class Method Summary collapse

Class Method Details

.delete_both(branch_name, confirm = true, git = nil) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/core/git_delete.rb', line 73

def self.delete_both(branch_name, confirm = true, git = nil)

    @git = git.nil? ? App::Git.new : git

    App::Terminal::output("Must check that branch is up-to-date with it's remote counter-part, otherwise DO NOT delete!", App::Terminal::MSG_TODO)
    App::Terminal::output('Must check branch even exists.', App::Terminal::MSG_TODO)

    if confirm
        unless App::Terminal::prompt_yes_no("#{App::Terminal::format_action('locally & remotely delete')} branch #{App::Terminal::format_branch(branch_name)}?")
            App::Terminal::abort
        end
    end

    @git.repo_loop.each do |repo_dir|
        if @git.current_branch_for_repo(repo_dir) == branch_name
            App::Terminal::command("git checkout #{App::Git::MASTER}", repo_dir)
        end

        commands = [
            "git branch --unset-upstream #{branch_name}",
            "git branch -d #{branch_name}"
        ]
        results = App::Terminal::command(commands, repo_dir)
        handle_results_1(branch_name, repo_dir, results)

        commands = [
            "git push origin --delete  #{branch_name}"
        ]
        results = App::Terminal::command(commands, repo_dir)
        handle_results_2(branch_name, repo_dir, results)

    end

    App::Terminal::success('Branch deleted', "Successfully #{App::Terminal::format_highlight('locally')} and #{App::Terminal::format_highlight('remotely')} #{App::Terminal::format_action('deleted')} branch #{App::Terminal::format_branch(branch_name)}")

end

.delete_local(branch_name, confirm = true, git = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/core/git_delete.rb', line 5

def self.delete_local(branch_name, confirm = true, git = nil)

    @git = git.nil? ? App::Git.new : git

    branch_info = @git.branch_data(branch_name)

    App::Terminal::output("Must check that branch is up-to-date with it's remote counter-part, otherwise DO NOT delete!", App::Terminal::MSG_TODO)
    App::Terminal::output('Must check branch even exists.', App::Terminal::MSG_TODO)

    if confirm
        unless App::Terminal::prompt_yes_no("#{App::Terminal::format_action('locally delete')} branch #{App::Terminal::format_branch(branch_name)}?")
            App::Terminal::abort
        end
    end

    @git.repo_loop.each do |repo_dir|
        if @git.current_branch_for_repo(repo_dir) == branch_name
            App::Terminal::command("git checkout #{App::Git::MASTER}", repo_dir)
        end
        if (repo_dir == App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_CODE) && branch_info[0][:"#{App::Git::BRANCH_EXISTS_LOCALLY}"]) || (repo_dir == App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_CODE) && branch_info[0][:"#{App::Git::BRANCH_EXISTS_LOCALLY}"])
            commands = [
                "git branch --unset-upstream #{branch_name}",
                "git branch -d #{branch_name}"
            ]
            results = App::Terminal::command(commands, repo_dir)
            handle_results_1(branch_name, repo_dir, results)
        else
            App::Terminal::output("Skipping #{App::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))} because branch #{App::Terminal::format_branch(branch_name)} doesn't exist there.", App::Terminal::MSG_WARNING)
        end

    end

    App::Terminal::success('Branch deleted', "Successfully #{App::Terminal::format_highlight('locally')} #{App::Terminal::format_action('deleted')} branch #{App::Terminal::format_branch(branch_name)}")

end

.delete_remote(branch_name, confirm = true, git = nil) ⇒ Object



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
66
67
68
69
70
71
# File 'lib/core/git_delete.rb', line 41

def self.delete_remote(branch_name, confirm = true, git = nil)

    @git = git.nil? ? App::Git.new : git

    App::Terminal::output('Must check branch even exists.', App::Terminal::MSG_TODO)

    if confirm
        unless App::Terminal::prompt_yes_no("#{App::Terminal::format_action('remotely delete')} branch #{App::Terminal::format_branch(branch_name)}?")
            App::Terminal::abort
        end
    end

    @git.repo_loop.each do |repo_dir|
        unless @git.branch_exists(branch_name, repo_dir, App::Git::REMOTE)
            puts "Branch \x1B[32m[#{branch_name}]\x1B[0m not found in: \x1B[33m#{repo_dir}\x1B[0m. Aborting \x1B[35mREMOTE DELETE\x1B[0m for this repo."
            next
        end

        # This is hacky (but no time) !
        results = App::Terminal::command("git branch --unset-upstream #{branch_name}", repo_dir)
        results[1] = true
        handle_results_1(branch_name, repo_dir, results)

        results = App::Terminal::command("git push origin --delete #{branch_name}", repo_dir)
        handle_results_2(branch_name, repo_dir, results)

    end

    App::Terminal::success('Branch deleted', "Successfully #{App::Terminal::format_highlight('remotely')} #{App::Terminal::format_action('deleted')} branch #{App::Terminal::format_branch(branch_name)}")

end