Sha256: d173a16ed47bea02cc3dafb686b24cea6ef4a08b89be9eb19b79e20e73854994

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

module GGSM
  module Submodule
    def check_submodule
      sub_str = `git submodule`
      if sub_str.empty?
        puts '所在目录工程下不存在Submodule,请检查所在目录!'.red
        exit 1
      end
    end

    def get_submodule
      sub_status = `git submodule`
      pattern = /(?<=\s)[0-9a-zA-Z]*(?=\s)/
      sub_status = sub_status.split(/\n/)

      result = []
      sub_status.each do |sub|
        match = pattern.match(sub.strip)
        result.push(match[0])
      end
      return result
    end

    def get_submodule_commit
      sub_commits = `git ls-tree HEAD | grep "160000"`
      pattern = /(?<=\s)[0-9a-zA-Z]{40}(?=\s)/
      sub_commits = sub_commits.split(/\n/)
      result = []
      sub_commits.each do |sub|
        match = pattern.match(sub.strip)
        result.push(match[0][0...7])
      end
      return result
    end

    def check_un_commit_code
      subs = get_submodule
      subs.each do |sub|
        Dir.chdir sub
        status = `git status --ignore-submodules | grep 'nothing to commit'`
        if status.strip == ''
          puts "#{sub} 有未提交的代码".red
          exit 1
        end
        Dir.chdir '..'
      end

      status = `git status --ignore-submodules | grep 'nothing to commit'`
      if status.strip == ''
        puts '主工程 有未提交的代码'.red
        exit 1
      end
    end

    def get_current_branch
      return `git branch | grep "*"`.split('* ')[1].split("\n")[0]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ggsm-1.2.0 lib/ggsm/util/submodule.rb
ggsm-1.1.2 lib/ggsm/util/submodule.rb
ggsm-1.1.1 lib/ggsm/util/submodule.rb
ggsm-1.1.0 lib/ggsm/util/submodule.rb