-
Notifications
You must be signed in to change notification settings - Fork 119
/
extract_git_commit_number.vbs
51 lines (38 loc) · 1.22 KB
/
extract_git_commit_number.vbs
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
Function getCommandOutput(theCommand)
Dim objShell, objCmdExec
Set objShell = CreateObject("WScript.Shell")
Set objCmdExec = objshell.exec(thecommand)
getCommandOutput = objCmdExec.StdOut.ReadAll
end Function
'Read text file
function GetFile(FileName)
If FileName<>"" Then
Dim FS, FileStream
Set FS = CreateObject("Scripting.FileSystemObject")
on error resume Next
Set FileStream = FS.OpenTextFile(FileName)
GetFile = FileStream.ReadAll
End If
End Function
'Write string As a text file.
function WriteFile(FileName, Contents)
Dim OutStream, FS
on error resume Next
Set FS = CreateObject("Scripting.FileSystemObject")
Set OutStream = FS.OpenTextFile(FileName, 2, True)
OutStream.Write Contents
End Function
InputFile = WScript.Arguments(0)
OutputFile = WScript.Arguments(1)
revCount = getCommandOutput("git rev-list HEAD --count")
IF (IsNumeric(revCount)) THEN
revCount = Replace(revCount, vbCr, "")
revCount = Replace(revCount, vbLf, "")
'Wscript.Echo revCount
'Read source text file
FileContents = GetFile(InputFile)
ReplacedContents = Replace(FileContents, "$REVNUM$", revCount, 1, -1, 1)
WriteFile OutputFile, ReplacedContents
ELSE
WriteFile OutputFile, ""
END IF