Class: Pixab::FeatureStart

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

Instance Method Summary collapse

Constructor Details

#initialize(isNeedPush) ⇒ FeatureStart

Returns a new instance of FeatureStart.



8
9
10
# File 'lib/feature/FeatureStart.rb', line 8

def initialize(isNeedPush)
  @isNeedPush = isNeedPush
end

Instance Method Details

#create_feature_branch(feature_name) ⇒ Object



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

def create_feature_branch(feature_name)
  if !GitUtils.is_git_repo
    puts "当前目录不是 Git 仓库!, path: #{Dir.pwd}".red
    return
  end

  remote_develop_branch = GitUtils.get_remote_branch_name('develop')
  if remote_develop_branch.nil?
    puts "远程仓库不存在 develop 分支!".red
    return
  end

  GitUtils.fetch_origin('develop')

  `git checkout -b #{feature_name} #{remote_develop_branch}`

  # 是否需要推送到远程仓库
  if @isNeedPush 
    `git push -u origin #{feature_name}`
  end

end

#run(path, feature_name) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/feature/FeatureStart.rb', line 12

def run(path, feature_name)
  unless Dir.exist?(path)
    puts "当前目录不存在: #{path}".red
    return
  end

  puts "\n#{File.basename(path)} 开始创建分支: #{feature_name}\n".green

  Dir.chdir(path) do
    create_feature_branch(feature_name)
  end
end