Class: CommitCraft::GitClient
- Inherits:
-
Object
- Object
- CommitCraft::GitClient
- Defined in:
- lib/commitcraft/git_client.rb
Instance Method Summary collapse
- #all_diff ⇒ Object
- #commit(message, amend: false) ⇒ Object
- #current_branch ⇒ Object
- #file_stats ⇒ Object
-
#initialize(repo_path: Dir.pwd) ⇒ GitClient
constructor
A new instance of GitClient.
- #recent_commits(count = 5) ⇒ Object
- #staged_diff ⇒ Object
- #staged_files ⇒ Object
- #status ⇒ Object
- #unstaged_diff ⇒ Object
Constructor Details
#initialize(repo_path: Dir.pwd) ⇒ GitClient
Returns a new instance of GitClient.
6 7 8 9 |
# File 'lib/commitcraft/git_client.rb', line 6 def initialize(repo_path: Dir.pwd) @repo_path = repo_path validate_git_repo! end |
Instance Method Details
#all_diff ⇒ Object
22 23 24 |
# File 'lib/commitcraft/git_client.rb', line 22 def all_diff execute_command("git diff HEAD") end |
#commit(message, amend: false) ⇒ Object
38 39 40 41 42 |
# File 'lib/commitcraft/git_client.rb', line 38 def commit(, amend: false) = .gsub("'", "'\\''") cmd = amend ? "git commit --amend -m '#{escaped_message}'" : "git commit -m '#{escaped_message}'" execute_command(cmd) end |
#current_branch ⇒ Object
30 31 32 |
# File 'lib/commitcraft/git_client.rb', line 30 def current_branch execute_command("git branch --show-current").strip end |
#file_stats ⇒ Object
48 49 50 51 |
# File 'lib/commitcraft/git_client.rb', line 48 def file_stats stats = execute_command("git diff --cached --numstat") parse_file_stats(stats) end |
#recent_commits(count = 5) ⇒ Object
34 35 36 |
# File 'lib/commitcraft/git_client.rb', line 34 def recent_commits(count = 5) execute_command("git log -#{count} --oneline").split("\n") end |
#staged_diff ⇒ Object
11 12 13 14 15 16 |
# File 'lib/commitcraft/git_client.rb', line 11 def staged_diff diff = execute_command("git diff --cached") raise NoChangesError, "No staged changes found. Use 'git add' to stage your changes." if diff.empty? diff end |
#staged_files ⇒ Object
44 45 46 |
# File 'lib/commitcraft/git_client.rb', line 44 def staged_files execute_command("git diff --cached --name-only").split("\n") end |
#status ⇒ Object
26 27 28 |
# File 'lib/commitcraft/git_client.rb', line 26 def status execute_command("git status --short") end |
#unstaged_diff ⇒ Object
18 19 20 |
# File 'lib/commitcraft/git_client.rb', line 18 def unstaged_diff execute_command("git diff") end |