-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathStart-Git.psm1
90 lines (78 loc) · 2.11 KB
/
Start-Git.psm1
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
#Requires -Version 2.0
# --------------------------------
# << DESCRIPTION >>
#
# - git pull utilities for images
#
# << SUMMARY >>
#
# - Sync image files with git with following commands
#
# 1. git pull
# : pull latest file from remote repository
#
# --------------------------------
function Start-Git{
[CmdletBinding(
SupportsShouldProcess = $false,
ConfirmImpact = "none",
DefaultParameterSetName = "")]
param
(
[Parameter(
HelpMessage = "Input Full path of Git",
Position = 0,
Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true)]
[string[]]
$GitPath,
[Parameter(
HelpMessage = "Input path of Log",
Position = 1,
Mandatory = $false,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true)]
[string]
$LogPath,
[Parameter(
HelpMessage = "Input name of Log",
Position = 2,
Mandatory = $false,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[string]
$LogName
)
Begin
{
# Check for git directory
if (!(Test-Path $LogPath))
{
New-Item -ItemType Directory -Path $LogPath
}
$logFullPath = Join-Path $LogPath $logName
}
process
{
foreach ($path in $GitPath)
{
Push-Location $path
"{0} : Current Repository is '{1}'" -f (Get-Date), (Split-Path $path -Leaf) | Set-Content -PassThru -Path $logFullPath -Force
try
{
git pull | Add-Content -PassThru -Path $logFullPath -Force
}
catch
{
$_ | Add-Content -PassThru -Path $logFullPath -Force
}
finally
{
[System.Environment]::NewLine | Add-Content -PassThru -Path $logFullPath -Force
Pop-Location
}
}
}
}