Class: Makit::Git::CLI
- Inherits:
-
Object
- Object
- Makit::Git::CLI
- Defined in:
- lib/makit/git/cli.rb
Overview
This class provides methods for executing git commands and operations that modify repository state.
Class Method Summary collapse
- .integrate ⇒ Object
- .pull ⇒ Object
- .sync ⇒ Object
- .tag(version) ⇒ Object
- .zip_source_files(zipfilename) ⇒ Object
Class Method Details
.integrate ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/makit/git/cli.rb', line 9 def self.integrate return unless Repository.git_repo? && !Repository.detached ## check for unstaged or untracked files unstaged_files = `git status --porcelain`.split("\n") untracked_files = `git ls-files --others --exclude-standard`.split("\n") return unless unstaged_files.length.positive? || untracked_files.length.positive? "git add .".run "git commit -m \"integrate\"".run unless Repository.clean? end |
.pull ⇒ Object
53 54 55 56 57 |
# File 'lib/makit/git/cli.rb', line 53 def self.pull return unless Repository.git_repo? && !Repository.detached "git pull".try end |
.sync ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/makit/git/cli.rb', line 21 def self.sync return unless Repository.git_repo? && !Repository.detached "git pull".try "git push origin".try # Check which tags need to be pushed (exist locally but not remotely) = `git tag -l`.strip.split("\n").reject(&:empty?) = `git ls-remote --tags origin 2>/dev/null`.strip = if .empty? [] else # Extract tag names, removing refs/tags/ prefix and ^{} suffix, then get unique values .split("\n") .map { |line| line.split("\t").last } .select { |ref| ref.start_with?('refs/tags/') && !ref.end_with?('^{}') } .map { |ref| ref.sub('refs/tags/', '') } .uniq end = - if .empty? Makit::Logging.default_logger.info("All tags already exist on remote, skipping tag push") else Makit::Logging.default_logger.info("Pushing #{.length} tag(s) to remote: #{.join(', ')}") .each do |tag| "git push origin #{tag}".try end end end |
.tag(version) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/makit/git/cli.rb', line 63 def self.tag(version) # only tag if the repo is not read only if Repository.read_only? puts " cannot tag a read only repo".colorize(:red) return end # check if a tag for the current version already exists if `git tag -l v#{version}`.strip.length.positive? puts " tag v#{version} already exists".colorize(:red) else "git tag -a v#{version} -m \"version #{version}\"".run end end |
.zip_source_files(zipfilename) ⇒ Object
59 60 61 |
# File 'lib/makit/git/cli.rb', line 59 def self.zip_source_files(zipfilename) "git archive --format zip --output #{zipfilename} HEAD".run end |