本周日【珠海源创会】一起聊聊:PingCAP分布式事务、支付宝移动端实践、GSBN技术框架选型,点此报名占座

oscstudio / git-securePowerShellMIT

0 Watch 6 Star 15 Fork 9
commit.ps1 3.16 KB · 1 Lines
一键复制 编辑 Web IDE 原始数据 标准视图 历史
1 #### ---->
2
3 #
4 # git diff currentid between
5
6 $PrefixDir = Split-Path -Parent $PSScriptRoot
7 Import-Module -Name "$PrefixDir/modules/AesProvider"
8 Import-Module -Name "$PrefixDir/modules/Git"
9 Import-Module -Name "$PrefixDir/modules/Process"
10
11 $workdir = Get-WorktreeDir
12 $gitdir = Get-CurrentGitDir -Worktree $workdir
13
14 #$env:GIT_SECURE_COMMIT = "Execute"
15
16 Pop-Location
17 Set-Location $workdir
18
19 $result = ProcessArgv -FilePath git -ArgumentList $args
20 if ($result -ne 0) {
21 exit $result
24 $aeskey = git --git-dir=`"$gitdir/secure/.git`" config "aes.key"
25
26 if ($null -eq $aeskey) {
27 $aeskey = Read-Host "Please input your aes key"
28 }
29
30
31 $op = Get-Content -ErrorAction Ignore -Path "$gitdir/pointer.json"|ConvertFrom-Json
32
33 $gitfiles = @(
34 ".gitmodules",
35 ".gitignore",
36 ".gitattributes"
40 if ($null -eq $op) {
41 Write-Host "Initialize secure commit"
42 git ls-tree -r HEAD|ForEach-Object {
43 $obj = -Split $_
44 $file = $obj[3]
45 $sfile = "$gitdir/secure/$file"
46 if ($gitfiles.Contains($file)) {
47 Copy-Item "$workdir/$file" -Destination "$gitdir/secure/$file" -Force
48 return ## ForEach-Object need return
49 }
50 $sdir = Split-Path -Path $sfile
51 $res = New-Item -ItemType Directory -Force -Path $sdir
52 if ($null -eq $res) {
53 Write-Host -ForegroundColor Red "create dir: $sdir"
54 return ## ForEach-Object need return
56 $ret = New-AesFile -File $file -Key $aeskey -Destination $sfile
57 if ($ret -ne 0) {
58 Write-Host -ForegroundColor Red "AES failed"
59 }
60 else {
61 Write-Host -ForegroundColor Green "Encrypt $file done"
62 }
64 }
65 else {
66 Write-Host "Add commit to secure track"
67 Get-Changeset -Commit $op.wid|ForEach-Object {
68 $file = $_["path"]
70 if ($_["status"] -eq "D") {
71 Write-Host -ForegroundColor Yellow "Delete $file done"
72 Remove-Item -Path "$gitdir/secure/$file" -Force -ErrorAction Ignore
73 return ## ForEach-Object need return
76 if ($gitfiles.Contains($file)) {
77 Write-Host -ForegroundColor Green "sync git file: $file"
78 Remove-Item -Path "$gitdir/secure/$file" -Force -ErrorAction Ignore
79 Copy-Item "$workdir/$file" -Destination "$gitdir/secure/$file" -Force
80 return ## ForEach-Object need return
83 $ret = New-AesFile -File $file -Key $aeskey -Destination "$gitdir/secure/$file"
84 if ($ret -ne 0) {
85 Write-Host -ForegroundColor Red "AES encrypt file '$file' throw exception"
87 else {
88 Write-Host -ForegroundColor Green "Encrypt $file done"
89 }
90 # end block
94 $worktreecommit = git rev-parse HEAD
95 $message = git log --pretty=format:'%s' -n 1 $worktreecommit
99 $CurrentDir = $PWD
100 Set-Location "$gitdir/secure"
101 &git add -A
102 if ($LASTEXITCODE -ne 0) {
103 exit $LASTEXITCODE
104 }
105 &git commit -m "$message"
106 if ($LASTEXITCODE -ne 0) {
107 exit $LASTEXITCODE
108 }
109 $securecommit = git rev-parse HEAD
110
111 Set-Location $CurrentDir
112
113
114 $pointer = @{}
115 $pointer["sid"] = $securecommit
116 $pointer["wid"] = $worktreecommit
118 ConvertTo-Json -InputObject $pointer|Out-File "$gitdir/pointer.json"

搜索帮助

12_float_left_people 12_float_left_close