Class: AppCommand::GitStash

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

Instance Method Summary collapse

Instance Method Details

#executeObject



5
6
7
8
9
10
11
12
13
# File 'lib/routes/git_stash.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_stash.rb', line 19

def opts_routing

    show_all_stashes

end

#opts_validateObject



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

def opts_validate

end

#show_all_stashesObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/routes/git_stash.rb', line 25

def show_all_stashes

    no_stash_found_count = 0
    @git.repo_loop.each do |repo_dir|
        stashes = `cd #{repo_dir} && git stash list`
        stashes = stashes.split("\n")
        # Skip if no stashes.
        if stashes.any?
            App::Terminal::info("Showing stashes for: #{App::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))}")
            stashes.each do |stash|
                stash_name = stash.split(/:/).first
                output = App::Terminal::command_capture("git stash show --name-only #{stash_name}", repo_dir, false)
                App::Terminal::info("#{stash}", output[0], false)
            end
        else
            App::Terminal::info("No stashes found in: #{App::Terminal::format_directory(@git.get_repo_shorthand(repo_dir))}", nil, (no_stash_found_count > 0) ? false : true)
            no_stash_found_count = no_stash_found_count + 1
        end
    end

end