Class: BBItools::GitSets

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-bb-PodAssistant/tools/git_sets.rb

Class Method Summary collapse

Class Method Details

.commit_msg_init(args) ⇒ 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
40
# File 'lib/cocoapods-bb-PodAssistant/tools/git_sets.rb', line 5

def self.commit_msg_init(args)
    # folder_path = args[0]
    # if folder_path.nil?
    #     puts "传入的参数不能为空".red
    #     return
    # end
    # if !File::directory?(folder_path)
    #     puts "参数不是文件夹".red
    #     return
    # end
    puts "开始配置CommitLint,用于校验commit message的工具...".yellow
    system('touch ./.git/commit_msg')
    system('git config commit.template "`pwd`/.git/commit_msg"')
    a = <<-EOF
#!/bin/sh
echo "$(git symbolic-ref --short HEAD) subject" > `pwd`/.git/commit_msg
echo "" >> `pwd`/.git/commit_msg
echo "Cause:" >> `pwd`/.git/commit_msg
echo "Solution:" >> `pwd`/.git/commit_msg
echo "Releated Doc Address:" >> `pwd`/.git/commit_msg
echo  '''\n#TYPE类型\n#新功能       feature/feat\n#bug修复      bugfix/fixbug/fix\n#性能优化     perf\n#代码重构     refactor/review\n#线上修复     hotfix\n#发布版本     release\n#文档变更     docs\n#更新     update\n#新增     add\n#标签     tag\n#代码回退     revert\n#更新lock     lock''' >> `pwd`/.git/commit_msg
    EOF
    File.open('.git/hooks/pre-commit', 'w') do |f|
        f.puts a
    end
    puts "写入CommitLint规则"
    logo_path = File.join( File.dirname(__FILE__), 'temple-commit-msg.dat' )
    content = File.read( logo_path )
    File.open('.git/hooks/commit-msg', 'w') do |f|
        f.puts content
    end
    puts "更新权限"
    system('chmod a+x .git/hooks/pre-commit')
    system('chmod a+x .git/hooks/commit-msg')
    puts "配置成功,后续请直接使用git commit ,不要加 -m".green
end