Class: GitNext

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

Constant Summary collapse

CONFIG_FILE =
"/.git/gitnext.config"

Class Method Summary collapse

Class Method Details

.run(current_path, args = "") ⇒ Object



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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/git_next.rb', line 8

def self.run current_path, args=""
  usage_message = "Usage: gitnext [help, init, prev, top, bottom]"
  @current_path = current_path
  if File.exists? File.join @current_path, ".git"
    @git = Git.open @current_path

    if File.exist?(@current_path + CONFIG_FILE)
      case args
        when "top"
          message = "Moved to top"
          go_to 0
        when "prev"
          message = "Moved to previous"
          position = config_read_position
          go_to position + 1 if position < get_repo_length
        when "bottom"
          message = "Moved to bottom"
          go_to get_repo_length
        when "init"
          message = init()
        when "remove"
          go_to 0
          File.delete @current_path + CONFIG_FILE
          message = "Gitnext Removed"
        else
          if args.to_s.empty?
            message = "Moving to Next"
            position = config_read_position
            go_to position - 1 if position > 0
            git_show = `git show --stat`.split("\n")

            3.times { git_show.delete_at 1 }
            git_show.pop
            message += "\n" + git_show.compact.join("\n")
          else
            message = usage_message
          end
      end
    else
      case args
        when "init"
          message = init()
        when "help"
          message = usage_message
        else
          message = "GitNext not initialised"
      end
    end
  else
    message = "Not a git directory\n" + usage_message
  end
  message
end