Class: DesignShell::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/designshell/repo.rb

Constant Summary collapse

GIT_METHODS =
[:commit,:add,:reset_hard,:path,:clone,:log,:size,:branches,:status,:remotes,:pull,:fetch,:push,:merge]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aDesignShell = nil) ⇒ Repo

Returns a new instance of Repo.



12
13
14
# File 'lib/designshell/repo.rb', line 12

def initialize(aDesignShell=nil)
	@ds = aDesignShell
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/designshell/repo.rb', line 16

def method_missing(sym, *args, &block)
	if @git && GIT_METHODS.include?(sym)
		@git.send sym, *args, &block
	else
		super
	end
end

Instance Attribute Details

#configuredObject (readonly)

Returns the value of attribute configured.



8
9
10
# File 'lib/designshell/repo.rb', line 8

def configured
  @configured
end

#gitObject (readonly)

Returns the value of attribute git.



8
9
10
# File 'lib/designshell/repo.rb', line 8

def git
  @git
end

Instance Method Details

#branchObject



92
93
94
# File 'lib/designshell/repo.rb', line 92

def branch
	@git.current_branch
end

#changesBetweenCommits(aFromCommit, aToCommit) ⇒ Object

git –no-pager diff –name-status 26bb87c3981 191d64820f2b result is array of paths prefixed with status letter then a tab see git-scm.com/docs/git-diff under –diff-filter= Added (A), Copied ©, Deleted (D), Modified (M), Renamed ®, have their type (i.e. regular file, symlink, submodule, …) changed (T)



104
105
106
# File 'lib/designshell/repo.rb', line 104

def changesBetweenCommits(aFromCommit, aToCommit)
	@git.lib.command_lines('diff',['--name-status',aFromCommit,aToCommit])
end

#checkout(commit = nil, branch = nil) ⇒ Object



82
83
84
85
86
87
88
89
90
# File 'lib/designshell/repo.rb', line 82

def checkout(commit=nil,branch=nil)
	specific_commit = !!commit && !commit.index('HEAD')
	if specific_commit
		@git.checkout commit
	else
		branch ||= 'master'
		@git.checkout(branch)
	end
end

#clone(aUrl, aPath) ⇒ Object



37
38
39
# File 'lib/designshell/repo.rb', line 37

def clone(aUrl,aPath)
	@git = Git::clone(aUrl,aPath)
end

#commit_all(*args) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/designshell/repo.rb', line 49

def commit_all(*args)
	result = begin
		@git.commit_all(*args)
	rescue Git::GitExecuteError => e
		if e.message.index("nothing to commit (working directory clean)")
			nil
		else
			raise e
		end
	end
	result = commitFromString(result)
	result
end

#commitFromString(aString) ⇒ Object

“[master (root-commit) 6bdd9e1] first commit 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 file1.txt”



64
65
66
67
68
# File 'lib/designshell/repo.rb', line 64

def commitFromString(aString)
	return nil if !aString || aString.empty?
	sha = aString.scan(/ ([a-f0-9]+)\]/).flatten.first
	@git.gcommit(sha)
end

#empty?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/designshell/repo.rb', line 45

def empty?
	!@git.branches[0]
end

#get_file_content(aPath, aCommitOrBranch = nil) ⇒ Object



108
109
110
# File 'lib/designshell/repo.rb', line 108

def get_file_content(aPath,aCommitOrBranch=nil)
	@git.lib.command('show',[[aCommitOrBranch||'master',aPath].join(':')]) rescue nil
end

#headObject



96
97
98
# File 'lib/designshell/repo.rb', line 96

def head
	@git.log.first
end

#init(*args) ⇒ Object



33
34
35
# File 'lib/designshell/repo.rb', line 33

def init(*args)
	@git = Git.init(*args)
end

#open(aPath) ⇒ Object

def configure(aContext=nil) # set @path end



29
30
31
# File 'lib/designshell/repo.rb', line 29

def open(aPath)
	@git = Git.open(aPath, :log => Logger.new(STDOUT))
end

#open?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/designshell/repo.rb', line 41

def open?
	!!@git
end

#originObject



74
75
76
# File 'lib/designshell/repo.rb', line 74

def origin
	@git.remotes.find {|r| r.name=='origin'}
end

#pathObject



70
71
72
# File 'lib/designshell/repo.rb', line 70

def path
	@git.dir.path
end

#urlObject



78
79
80
# File 'lib/designshell/repo.rb', line 78

def url
	(o = origin) && o.url
end