Module: Legion::Extensions::Exec::Runners::Git
- Defined in:
- lib/legion/extensions/exec/runners/git.rb
Overview
rubocop:disable Legion/Extension/RunnerIncludeHelpers
Class Method Summary collapse
- .add(path:, files: '.') ⇒ Object
- .checkout(path:, ref:, create: false) ⇒ Object
- .clone(url:, path:, depth: nil, branch: nil) ⇒ Object
- .commit(path:, message:) ⇒ Object
- .create_repo(name:, org: 'LegionIO', description: '', public: true) ⇒ Object
- .fetch(path:, remote: nil) ⇒ Object
- .init(path:) ⇒ Object
- .push(path:, remote: 'origin', branch: 'main', set_upstream: false) ⇒ Object
- .status(path:) ⇒ Object
Class Method Details
.add(path:, files: '.') ⇒ Object
16 17 18 19 |
# File 'lib/legion/extensions/exec/runners/git.rb', line 16 def add(path:, files: '.', **) cmd = files == '.' ? 'git add -A' : "git add #{Array(files).join(' ')}" Runners::Shell.execute(command: cmd, cwd: path) end |
.checkout(path:, ref:, create: false) ⇒ Object
62 63 64 65 |
# File 'lib/legion/extensions/exec/runners/git.rb', line 62 def checkout(path:, ref:, create: false, **) flag = create ? ' -b' : '' Runners::Shell.execute(command: "git checkout#{flag} #{Shellwords.shellescape(ref)}", cwd: path) end |
.clone(url:, path:, depth: nil, branch: nil) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/legion/extensions/exec/runners/git.rb', line 47 def clone(url:, path:, depth: nil, branch: nil, **) resolved_depth = depth resolved_depth ||= Legion::Settings.dig(:fleet, :git, :depth) if defined?(Legion::Settings) args = ['git clone'] args << "--depth #{resolved_depth}" if resolved_depth args << "--branch #{Shellwords.shellescape(branch)}" if branch args << Shellwords.shellescape(url) << Shellwords.shellescape(path) Runners::Shell.execute(command: args.join(' '), cwd: Dir.pwd) end |
.commit(path:, message:) ⇒ Object
21 22 23 24 |
# File 'lib/legion/extensions/exec/runners/git.rb', line 21 def commit(path:, message:, **) safe_msg = .gsub("'", "\\'") Runners::Shell.execute(command: "git commit -m '#{safe_msg}'", cwd: path) end |
.create_repo(name:, org: 'LegionIO', description: '', public: true) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/legion/extensions/exec/runners/git.rb', line 39 def create_repo(name:, org: 'LegionIO', description: '', public: true, **) visibility = public ? '--public' : '--private' Runners::Shell.execute( command: "gh repo create #{org}/#{name} #{visibility} --description '#{description}' --clone", cwd: Dir.pwd ) end |
.fetch(path:, remote: nil) ⇒ Object
57 58 59 60 |
# File 'lib/legion/extensions/exec/runners/git.rb', line 57 def fetch(path:, remote: nil, **) cmd = remote ? "git fetch #{Shellwords.shellescape(remote)} --prune" : 'git fetch --all --prune' Runners::Shell.execute(command: cmd, cwd: path) end |
.init(path:) ⇒ Object
12 13 14 |
# File 'lib/legion/extensions/exec/runners/git.rb', line 12 def init(path:, **) Runners::Shell.execute(command: 'git init', cwd: path) end |
.push(path:, remote: 'origin', branch: 'main', set_upstream: false) ⇒ Object
26 27 28 29 |
# File 'lib/legion/extensions/exec/runners/git.rb', line 26 def push(path:, remote: 'origin', branch: 'main', set_upstream: false, **) cmd = set_upstream ? "git push -u #{remote} #{branch}" : 'git push' Runners::Shell.execute(command: cmd, cwd: path) end |
.status(path:) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/legion/extensions/exec/runners/git.rb', line 31 def status(path:, **) result = Runners::Shell.execute(command: 'git status --porcelain', cwd: path) return result unless result[:success] # rubocop:disable Legion/Extension/RunnerReturnHash parsed = Helpers::ResultParser.parse_git_status(result[:stdout] || '') result.merge(parsed: parsed) end |