Module: Appydave::Tools::Dam::GitHelper
- Defined in:
- lib/appydave/tools/dam/git_helper.rb
Overview
Git operations helper for DAM classes Provides reusable git command wrappers
Class Method Summary collapse
-
.commits_ahead(repo_path) ⇒ Integer
Count commits ahead of remote.
-
.commits_behind(repo_path) ⇒ Integer
Count commits behind remote.
-
.current_branch(repo_path) ⇒ String
Get current branch name.
-
.fetch(repo_path) ⇒ Boolean
Fetch from remote.
-
.modified_files_count(repo_path) ⇒ Integer
Count modified files.
-
.remote_url(repo_path) ⇒ String?
Get git remote URL.
-
.uncommitted_changes?(repo_path) ⇒ Boolean
Check if repository has uncommitted changes.
-
.untracked_files_count(repo_path) ⇒ Integer
Count untracked files.
Class Method Details
.commits_ahead(repo_path) ⇒ Integer
Count commits ahead of remote
34 35 36 37 38 |
# File 'lib/appydave/tools/dam/git_helper.rb', line 34 def commits_ahead(repo_path) `git -C "#{repo_path}" rev-list --count @{upstream}..HEAD 2>/dev/null`.strip.to_i rescue StandardError 0 end |
.commits_behind(repo_path) ⇒ Integer
Count commits behind remote
43 44 45 46 47 |
# File 'lib/appydave/tools/dam/git_helper.rb', line 43 def commits_behind(repo_path) `git -C "#{repo_path}" rev-list --count HEAD..@{upstream} 2>/dev/null`.strip.to_i rescue StandardError 0 end |
.current_branch(repo_path) ⇒ String
Get current branch name
14 15 16 17 18 19 |
# File 'lib/appydave/tools/dam/git_helper.rb', line 14 def current_branch(repo_path) result = `git -C "#{repo_path}" rev-parse --abbrev-ref HEAD 2>/dev/null`.strip result.empty? ? 'unknown' : result rescue StandardError 'unknown' end |
.fetch(repo_path) ⇒ Boolean
Fetch from remote
80 81 82 83 84 85 |
# File 'lib/appydave/tools/dam/git_helper.rb', line 80 def fetch(repo_path) system("git -C \"#{repo_path}\" fetch 2>/dev/null") $CHILD_STATUS.success? rescue StandardError false end |
.modified_files_count(repo_path) ⇒ Integer
Count modified files
52 53 54 55 56 |
# File 'lib/appydave/tools/dam/git_helper.rb', line 52 def modified_files_count(repo_path) `git -C "#{repo_path}" status --porcelain 2>/dev/null | grep -E "^.M|^M" | wc -l`.strip.to_i rescue StandardError 0 end |
.remote_url(repo_path) ⇒ String?
Get git remote URL
24 25 26 27 28 29 |
# File 'lib/appydave/tools/dam/git_helper.rb', line 24 def remote_url(repo_path) result = `git -C "#{repo_path}" remote get-url origin 2>/dev/null`.strip result.empty? ? nil : result rescue StandardError nil end |
.uncommitted_changes?(repo_path) ⇒ Boolean
Check if repository has uncommitted changes
70 71 72 73 74 75 |
# File 'lib/appydave/tools/dam/git_helper.rb', line 70 def uncommitted_changes?(repo_path) system("git -C \"#{repo_path}\" diff-index --quiet HEAD -- 2>/dev/null") !$CHILD_STATUS.success? rescue StandardError false end |
.untracked_files_count(repo_path) ⇒ Integer
Count untracked files
61 62 63 64 65 |
# File 'lib/appydave/tools/dam/git_helper.rb', line 61 def untracked_files_count(repo_path) `git -C "#{repo_path}" status --porcelain 2>/dev/null | grep -E "^\\?\\?" | wc -l`.strip.to_i rescue StandardError 0 end |