Class: ProjMgr::Git

Inherits:
Scm
  • Object
show all
Defined in:
lib/projmgr/git.rb

Overview

A wrapper class for interacting with a git repository

Author:

Instance Attribute Summary

Attributes inherited from Scm

#path, #project, #root, #url

Instance Method Summary collapse

Methods inherited from Scm

#initialize, #inspect, #path_exists?, #project_parent_directory

Constructor Details

This class inherits a constructor from ProjMgr::Scm

Instance Method Details

#has_local_changes?Boolean

Checks for local changes in the target repository

Returns:

  • (Boolean)

    if there is local changes or not



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/projmgr/git.rb', line 50

def has_local_changes?
	if path_exists? == false
		return false, "path does not exists, please check the path or check it out"
	else
		results = `cd #{@path} && git status && cd #{@root}`

		if results !~ /nothing to commit/
			return true, "has local changes"
		elsif results =~ /Your branch is ahead of/
			return true, "has local changes"
		elsif results =~ /Untracked files/
			return true, "has local changes"
		else
			return false, "has no local changes"
		end
	end
end

#updateString

Checks for updates in the target repository

Returns:

  • (String)

    the results of ‘git pull’ on the target repository



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/projmgr/git.rb', line 33

def update
	if path_exists? == false
		return "path does not exists, cannot update repository"
	else
		results = `cd #{@path} && git pull && cd #{@root}`

		if results =~ /Already up-to-date./
			return "Already up-to-date!"
		else
			return results
		end
	end
end