指数
0
Watch 6 Star 16 Fork 11

oscstudio / git-securePowerShellMIT

commit.ps1
一键复制 编辑 Web IDE 原始数据 标准视图 历史
Force Charlie   fix shell path 2017-07-24
#### ---->#
Force Charlie   Rename module 2018-06-20
# git diff currentid between
Force Charlie   -h --help -v --version support 2017-07-25
$PrefixDir = Split-Path -Parent $PSScriptRoot
Force Charlie   Rename module 2018-06-20
Import-Module -Name "$PrefixDir/modules/AesProvider"Import-Module -Name "$PrefixDir/modules/Git"Import-Module -Name "$PrefixDir/modules/Process"
Force Charlie   clone use git ls-tree 2017-07-26
$workdir = Get-WorktreeDir$gitdir = Get-CurrentGitDir -Worktree $workdir#$env:GIT_SECURE_COMMIT = "Execute"Pop-LocationSet-Location $workdir
Force Charlie   add process module 2017-08-03
$result = ProcessArgv -FilePath git -ArgumentList $argsif ($result -ne 0) {    exit $result
Force Charlie   clone use git ls-tree 2017-07-26
}
Force Charlie   Rename module 2018-06-20
$aeskey = git --git-dir=`"$gitdir/secure/.git`" config "aes.key"
Force Charlie   clone use git ls-tree 2017-07-26
if ($null -eq $aeskey) {    $aeskey = Read-Host "Please input your aes key"}$op = Get-Content -ErrorAction Ignore -Path "$gitdir/pointer.json"|ConvertFrom-Json
Force Charlie   git-secure commit feature 2017-07-26
$gitfiles = @(
Force Charlie   fix ForEach-Object 2017-07-27
    ".gitmodules",
Force Charlie   git-secure commit feature 2017-07-26
    ".gitignore",
Force Charlie   fix ForEach-Object 2017-07-27
    ".gitattributes"
Force Charlie   git-secure commit feature 2017-07-26
)
Force Charlie   clone use git ls-tree 2017-07-26
Force Charlie   fix ForEach-Object 2017-07-27
Force Charlie   git-secure commit feature 2017-07-26
if ($null -eq $op) {    Write-Host "Initialize secure commit"    git ls-tree -r HEAD|ForEach-Object {        $obj = -Split $_        $file = $obj[3]        $sfile = "$gitdir/secure/$file"        if ($gitfiles.Contains($file)) {            Copy-Item "$workdir/$file" -Destination "$gitdir/secure/$file" -Force
Force Charlie   fix ForEach-Object 2017-07-27
            return ## ForEach-Object need return
Force Charlie   git-secure commit feature 2017-07-26
        }        $sdir = Split-Path -Path $sfile        $res = New-Item -ItemType Directory -Force -Path $sdir        if ($null -eq $res) {            Write-Host -ForegroundColor Red "create dir: $sdir"
Force Charlie   fix ForEach-Object 2017-07-27
            return ## ForEach-Object need return
Force Charlie   git-secure commit feature 2017-07-26
        }
Force Charlie   fix aes.key config read 2017-07-26
        $ret = New-AesFile -File $file -Key $aeskey -Destination $sfile        if ($ret -ne 0) {
Force Charlie   git-secure commit feature 2017-07-26
            Write-Host -ForegroundColor Red "AES failed"        }
Force Charlie   pull feature 2017-07-26
        else {            Write-Host -ForegroundColor Green "Encrypt $file done"        }
Force Charlie   git-secure commit feature 2017-07-26
    }
Force Charlie   clone use git ls-tree 2017-07-26
}else {
Force Charlie   git-secure commit feature 2017-07-26
    Write-Host "Add commit to secure track"    Get-Changeset -Commit $op.wid|ForEach-Object {        $file = $_["path"]
Force Charlie   fix ForEach-Object 2017-07-27
Force Charlie   git-secure commit feature 2017-07-26
        if ($_["status"] -eq "D") {
Force Charlie   fix ForEach-Object 2017-07-27
            Write-Host -ForegroundColor Yellow "Delete $file done"
Force Charlie   fix aes.key config read 2017-07-26
            Remove-Item -Path "$gitdir/secure/$file" -Force -ErrorAction Ignore
Force Charlie   fix ForEach-Object 2017-07-27
            return ## ForEach-Object need return
Force Charlie   clone use git ls-tree 2017-07-26
        }
Force Charlie   fix ForEach-Object 2017-07-27
Force Charlie   fix aes.key config read 2017-07-26
        if ($gitfiles.Contains($file)) {
Force Charlie   fix ForEach-Object 2017-07-27
            Write-Host -ForegroundColor Green "sync git file: $file"
Force Charlie   fix aes.key config read 2017-07-26
            Remove-Item -Path "$gitdir/secure/$file" -Force -ErrorAction Ignore            Copy-Item "$workdir/$file" -Destination "$gitdir/secure/$file" -Force
Force Charlie   fix ForEach-Object 2017-07-27
            return ## ForEach-Object need return
Force Charlie   fix aes.key config read 2017-07-26
        }
Force Charlie   fix ForEach-Object 2017-07-27
Force Charlie   fix aes.key config read 2017-07-26
        $ret = New-AesFile -File $file -Key $aeskey -Destination "$gitdir/secure/$file"        if ($ret -ne 0) {            Write-Host  -ForegroundColor Red "AES encrypt file '$file' throw exception"
Force Charlie   clone use git ls-tree 2017-07-26
        }
Force Charlie   fix args have space 2017-07-26
        else {            Write-Host -ForegroundColor Green "Encrypt $file done"        }
Force Charlie   fix ForEach-Object 2017-07-27
        # end block
Force Charlie   clone use git ls-tree 2017-07-26
    }}
Force Charlie   fix aes.key config read 2017-07-26
$worktreecommit = git rev-parse HEAD$message = git log --pretty=format:'%s' -n 1 $worktreecommit
Force Charlie   git-secure commit feature 2017-07-26
Force Charlie   fix ForEach-Object 2017-07-27
Force Charlie   fix aes.key config read 2017-07-26
$CurrentDir = $PWD
Force Charlie   git-secure commit feature 2017-07-26
Set-Location "$gitdir/secure"
Force Charlie   fix ForEach-Object 2017-07-27
&git add -A
Force Charlie   fix aes.key config read 2017-07-26
if ($LASTEXITCODE -ne 0) {
Force Charlie   git-secure commit feature 2017-07-26
    exit $LASTEXITCODE}&git commit -m "$message"if ($LASTEXITCODE -ne 0) {    exit $LASTEXITCODE}
Force Charlie   fix aes.key config read 2017-07-26
$securecommit = git rev-parse HEADSet-Location $CurrentDir$pointer = @{}$pointer["sid"] = $securecommit$pointer["wid"] = $worktreecommit
Force Charlie   Get-FileChanges 2017-07-25
Force Charlie   fix aes.key config read 2017-07-26
ConvertTo-Json -InputObject $pointer|Out-File "$gitdir/pointer.json"

搜索帮助