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(files = nil) ⇒ Object
- #get_staged_files ⇒ Object
- #repository_status ⇒ Object
Instance Method Details
#commit(message) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/git_auto/services/git_service.rb', line 25 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
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/git_auto/services/git_service.rb', line 32 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(files = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/git_auto/services/git_service.rb', line 10 def get_staged_diff(files = nil) validate_git_repository! if files files = [files] unless files.is_a?(Array) execute_git_command("diff", "--cached", "--", *files) else execute_git_command("diff", "--cached") end end |
#get_staged_files ⇒ Object
20 21 22 23 |
# File 'lib/git_auto/services/git_service.rb', line 20 def get_staged_files validate_git_repository! execute_git_command("diff", "--cached", "--name-only").split("\n") end |
#repository_status ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/git_auto/services/git_service.rb', line 52 def repository_status { has_staged_changes: has_staged_changes?, is_clean: is_clean?, has_commits: has_commits? } end |