-
Notifications
You must be signed in to change notification settings - Fork 4
/
git.cfc
112 lines (91 loc) · 3.47 KB
/
git.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<cfcomponent displayname="cfgit" hint="I interact with git" output="false">
<!--- The setup --->
<cfproperty
name="git_path"
displayname="Git path"
hint="On *nix system you can find the git to path by running $which git"
type="string" />
<cfproperty
name="git_folder"
displayname="Repository folder"
hint="I am the folder you are going to query"
type="string" />
<cffunction name="init" access="public" output="false" returntype="any" hint="I setup the CFC">
<cfargument name="argGit_path" type="string" required="true">
<cfargument name="arggit_folder" type="string" required="true">
<cfscript>
setGit_path( argGit_path );
setgit_folder( arggit_folder );
return this;
</cfscript>
</cffunction>
<!--- End: the setup --->
<!--- Commands --->
<cffunction name="add" access="public" output="false" returntype="any" hint="Add file contents to the index">
<cfargument
name="argFiles"
type="string"
default="."
hint="Limits the number of commits to show" />
<cfreturn execGit( "add", argFiles )>
</cffunction>
<cffunction name="diff" access="public" output="false" returntype="any">
<cfreturn execGit( "diff" )>
</cffunction>
<cffunction name="log" access="public" output="false" returntype="any" hint="log">
<cfargument
name="argN"
type="numeric"
default="5"
hint="Limits the number of commits to show" />
<cfif len( trim( argN )) AND isValid( "integer", argN )>
<cfset argN = "-n " & argN>
</cfif>
<cfreturn execGit( "log", argN )>
</cffunction>
<cffunction name="show" access="public" output="false" returntype="any" hint="Show various types of objects">
<cfreturn execGit( "show" )>
</cffunction>
<cffunction name="status" access="public" output="false" returntype="any" hint="Show the working tree status">
<cfreturn execGit( "status" )>
</cffunction>
<!--- End: Commands --->
<!--- wrapped up the execute in a function to save repetition --->
<cffunction name="execGit" access="public" output="false" returntype="string">
<cfargument name="argCommand" required="true" type="string">
<cfargument name="argArguments" required="false" type="string" default="">
<cfset var local = {} />
<cfexecute name = "#getGit_path()#"
arguments = "--git-dir=#getgit_folder()# #argCommand# #argArguments#"
timeout = "10"
variable="local.out"
errorvariable="local.err">
</cfexecute>
<cfif len( trim( local.err ) )>
<cfset local.msg = "error running Git command <b>$git #uCase(argCommand &" "&argArguments)#</b> in execGit()">
<cfthrow detail="#local.err#" type="git" message="#local.msg#" />
<cfelse>
<cfreturn local.out>
</cfif>
</cffunction>
<!--- Getters and Setters --->
<cffunction name="getGit_path" access="public" output="false" returntype="string">
<cfreturn git_path>
</cffunction>
<cffunction name="setGit_path" access="private" output="false" returntype="void">
<cfargument name="argGit_path" type="any">
<cfset git_path=argGit_path/>
</cffunction>
<cffunction name="getgit_folder" access="public" output="false" returntype="string">
<cfreturn git_folder>
</cffunction>
<cffunction name="setgit_folder" access="private" output="false" returntype="void">
<cfargument name="arggit_folder" type="any">
<cfscript>
// makse sure there is a trailing slash
if( right( arggit_folder, 1) NEQ "/"){ arggit_folder = arggit_folder & "/"; }
arggit_folder = arggit_folder & ".git";
git_folder=arggit_folder;
</cfscript>
</cffunction>
</cfcomponent>