Module: AIGit::Git
- Defined in:
- lib/ai_git/git.rb
Class Method Summary collapse
-
.commit_with_message(message) ⇒ Object
Commit using a temp file so the message can contain anything (quotes, backticks, dollar signs) without shell-escaping concerns.
- .current_branch ⇒ Object
- .diff ⇒ Object
- .push_current_branch ⇒ Object
-
.run_command(cmd, *args) ⇒ Object
Run a command with arguments as an array — no shell, so values are not interpolated or word-split.
- .staged_files ⇒ Object
Class Method Details
.commit_with_message(message) ⇒ Object
Commit using a temp file so the message can contain anything (quotes, backticks, dollar signs) without shell-escaping concerns.
43 44 45 46 47 48 49 50 |
# File 'lib/ai_git/git.rb', line 43 def () Tempfile.create("ai_git_commit_msg") do |file| file.write() file.flush run_command("git", "commit", "-F", file.path) end end |
.current_branch ⇒ Object
18 19 20 |
# File 'lib/ai_git/git.rb', line 18 def current_branch `git rev-parse --abbrev-ref HEAD`.chomp end |
.diff ⇒ Object
14 15 16 |
# File 'lib/ai_git/git.rb', line 14 def diff `git diff --cached` end |
.push_current_branch ⇒ Object
52 53 54 |
# File 'lib/ai_git/git.rb', line 52 def push_current_branch run_command("git", "push", "-u", "origin", "HEAD") end |
.run_command(cmd, *args) ⇒ Object
Run a command with arguments as an array — no shell, so values are not interpolated or word-split. Accepts either:
run_command("git", "status") (single string of args)
run_command("git", "commit", "-m", message) (variadic args, preferred)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ai_git/git.rb', line 26 def run_command(cmd, *args) argv = if args.length == 1 && args.first.is_a?(String) args.first.split else args.map(&:to_s) end _stdout, stderr, status = Open3.capture3(cmd, *argv) return if status.success? raise "Command failed: #{cmd} #{argv.join(' ')} (exit #{status.exitstatus})#{stderr.empty? ? '' : "\n#{stderr}"}" end |
.staged_files ⇒ Object
10 11 12 |
# File 'lib/ai_git/git.rb', line 10 def staged_files `git diff --cached --name-only` end |