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

Class Method Details

.commits_ahead(repo_path) ⇒ Integer

Count commits ahead of remote

Parameters:

  • repo_path (String)

    Path to git repository

Returns:

  • (Integer)

    Number of commits ahead



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

Parameters:

  • repo_path (String)

    Path to git repository

Returns:

  • (Integer)

    Number of commits behind



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

Parameters:

  • repo_path (String)

    Path to git repository

Returns:

  • (String)

    Branch name or ‘unknown’ if error



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

Parameters:

  • repo_path (String)

    Path to git repository

Returns:

  • (Boolean)

    true if successful



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

Parameters:

  • repo_path (String)

    Path to git repository

Returns:

  • (Integer)

    Number of 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

Parameters:

  • repo_path (String)

    Path to git repository

Returns:

  • (String, nil)

    Remote URL or nil if not configured



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

Parameters:

  • repo_path (String)

    Path to git repository

Returns:

  • (Boolean)

    true if changes exist



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

Parameters:

  • repo_path (String)

    Path to git repository

Returns:

  • (Integer)

    Number of 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