Class: Gitl::SubCommand

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

Direct Known Subclasses

Create, CreateTag, DeleteTag, Init, Review, Start, Sync

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

#error, handle_exception, #info, report_error, run

Constructor Details

#initialize(argv) ⇒ SubCommand

Returns a new instance of SubCommand.



21
22
23
24
25
26
27
# File 'lib/sub_command.rb', line 21

def initialize(argv)
  @yml = argv.option('config')
  if @yml.nil?
    @yml = 'Gitl.yml'
  end
  super
end

Instance Attribute Details

#gitl_configObject (readonly)

Returns the value of attribute gitl_config.



13
14
15
# File 'lib/sub_command.rb', line 13

def gitl_config
  @gitl_config
end

Class Method Details

.optionsObject



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

def self.options
  [
      ['--config=[Gitl.yml]', 'gitl配置, 默认为Gitl.yml'],
  ].concat(super)
end

Instance Method Details

#check_uncommit(g, project_name) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/sub_command.rb', line 92

def check_uncommit(g, project_name)
  changed = g.status.changed
  added = g.status.added
  deleted = g.status.deleted
  untracked = g.status.untracked

  if !changed.empty?
    alert = true
    puts "modified files:".red
    changed.each do |file, status|
      puts ("        M:        " << file).red
    end
  end

  if !added.empty?
    alert = true
    puts "added files:".red
    added.each do |file, status|
      puts ("        A:        " << file).red
    end
  end

  if !deleted.empty?
    alert = true
    puts "deleted files:".red
    deleted.each do |file, status|
      puts ("        D:        " << file).red
    end
  end

  if !untracked.empty?
    alert = true
    puts "untracked files:".red
    untracked.each do |file, status|
      puts ("        " << file).red
    end
  end

  if alert
    puts "exist uncommit files in current branch '#{g.current_branch}' for '#{project_name}'. ignore it? y/n "
    flag = STDIN.gets.chomp
    unless flag.downcase == "y"
      exit
    end
  end
end

#runObject



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/sub_command.rb', line 33

def run
  workspace_path = "./"
  find_workspace = false;
  begin
    result = nil
    Dir.chdir(workspace_path) do
      result = Dir.glob('.gitl', File::FNM_DOTMATCH)
    end
    if result.length > 0
      find_workspace = true
      break
    else
      workspace_path = File.expand_path("../", workspace_path)
    end
  end while workspace_path.length > 0 && workspace_path != "/"

  if find_workspace
    Dir.chdir(workspace_path) do
      self.run_in_workspace()
    end
  else
    raise Error.new("Current path is not gitl workspace.")
  end
end

#run_in_workspaceObject



58
59
60
# File 'lib/sub_command.rb', line 58

def run_in_workspace

end

#save_workspace_config(workspace_config) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/sub_command.rb', line 84

def save_workspace_config(workspace_config)
  filename = '.gitl'
  # workspace_config_path = File.expand_path(filename, File.dirname(self.gitl_config.config_path))
  workspace_config_path = filename
  workspace_config.save(workspace_config_path)
  @workspace_config = workspace_config
end

#validate!Object



29
30
31
# File 'lib/sub_command.rb', line 29

def validate!
  super
end

#workspace_configObject



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/sub_command.rb', line 71

def workspace_config
  if @workspace_config.nil?
    filename = '.gitl'
    # workspace_config_path = File.expand_path(filename, File.dirname(self.gitl_config.config_path))
    workspace_config_path = filename
    if !File.exist?(workspace_config_path)
      help! "workspace config not found. please run 'gitl start' first."
    end
    @workspace_config = WorkSpaceConfig.load_file(workspace_config_path)
  end
  @workspace_config
end