Class: YJCocoa::GitCache

Inherits:
Git
  • Object
show all
Defined in:
lib/yjcocoa/git/git_cache.rb

Constant Summary

Constants inherited from Command

Command::DEFAULT_OPTIONS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Git

#gitExist?

Methods inherited from Command

#askWithAnswers

Constructor Details

#initialize(argv) ⇒ GitCache

初始化



40
41
42
43
44
# File 'lib/yjcocoa/git/git_cache.rb', line 40

def initialize(argv)
    super
    self.paths = argv.option('delete-path')
    self.paths = self.paths.split(",").reject {|i| i.empty? } if self.paths
end

Instance Attribute Details

#pathsObject

property



37
38
39
# File 'lib/yjcocoa/git/git_cache.rb', line 37

def paths
  @paths
end

Class Method Details

.optionsObject



28
29
30
31
32
33
34
# File 'lib/yjcocoa/git/git_cache.rb', line 28

def self.options
    if self == YJCocoa::GitCache
        [['--delete-path', '删除的文件路径,多个路径用‘,’隔开']] + super
    else
        super
    end
end

Instance Method Details

#cleanRepositoryObject



80
81
82
83
84
# File 'lib/yjcocoa/git/git_cache.rb', line 80

def cleanRepository
    system("git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin")
    system("git reflog expire --expire=now --all")
    system("git gc --prune=now")
end

#cleanWorkDirectoryObject



65
66
67
68
69
70
71
72
73
# File 'lib/yjcocoa/git/git_cache.rb', line 65

def cleanWorkDirectory
    self.paths.each { |path|
        puts "YJCocoa git delete cache #{path}".green
        system("git filter-branch --force --index-filter \
               'git rm -r --cached --ignore-unmatch #{path}' \
               --prune-empty --tag-name-filter cat -- --all")
        puts
    }
end

#pushOriginObject



75
76
77
78
# File 'lib/yjcocoa/git/git_cache.rb', line 75

def pushOrigin
    system("git push origin --force --all")
    system("git push origin --force --tags")
end

#runObject



56
57
58
59
60
61
62
63
# File 'lib/yjcocoa/git/git_cache.rb', line 56

def run
    self.cleanWorkDirectory
    answer = self.askWithAnswers("强制推动您的本地更改覆盖您的远端仓库", ["Yes", "No"])
    if answer == "yes"
        self.pushOrigin
        self.cleanRepository
    end
end

#validate!Object

businrss



47
48
49
50
51
52
53
54
# File 'lib/yjcocoa/git/git_cache.rb', line 47

def validate!
    super
    exit 0 unless self.gitExist?
    unless self.paths
        puts "文件路径为空".red
        self.banner!
    end
end