Class: GitAuto::Services::GitService
- Inherits:
-
Object
- Object
- GitAuto::Services::GitService
- Defined in:
- lib/git_auto/services/git_service.rb
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
- #commit(message) ⇒ Object
- #get_commit_history(limit = nil) ⇒ Object
- #get_staged_diff ⇒ Object
- #get_staged_files ⇒ Object
- #repository_status ⇒ Object
Instance Method Details
#commit(message) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/git_auto/services/git_service.rb', line 20 def commit() validate_git_repository! validate_staged_changes! first_line = .split("\n").first.strip execute_git_command("commit", "-m", first_line) end |
#get_commit_history(limit = nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/git_auto/services/git_service.rb', line 27 def get_commit_history(limit = nil) validate_git_repository! format = "%H%n%s%n%an%n%aI" command = ["log", "--pretty=format:#{format}", "--no-merges"] command << "-#{limit}" if limit output = execute_git_command(*command) return [] if output.empty? output.split("\n\n").map do |commit| hash, subject, , date = commit.split("\n") { hash: hash, subject: subject, author: , date: date } end end |
#get_staged_diff ⇒ Object
10 11 12 13 |
# File 'lib/git_auto/services/git_service.rb', line 10 def get_staged_diff validate_git_repository! execute_git_command("diff", "--cached") end |
#get_staged_files ⇒ Object
15 16 17 18 |
# File 'lib/git_auto/services/git_service.rb', line 15 def get_staged_files validate_git_repository! execute_git_command("diff", "--cached", "--name-only").split("\n") end |
#repository_status ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/git_auto/services/git_service.rb', line 47 def repository_status { has_staged_changes: has_staged_changes?, is_clean: is_clean?, has_commits: has_commits? } end |