指数
0
Watch 6 Star 16 Fork 11

oscstudio / git-securePowerShellMIT

pull.ps1
一键复制 编辑 Web IDE 原始数据 标准视图 历史
Force Charlie   -h --help -v --version support 2017-07-25
#### pull from remote$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   fix args have space 2017-07-26
Force Charlie   fix clone push 2017-07-27
$gitfiles = @(
Force Charlie   pull feature 2017-07-26
    ".gitmodules",    ".gitignore",    ".gitattributes")$workdir = Get-WorktreeDir$gitdir = Get-CurrentGitDir -Worktree $workdir
Force Charlie   fix args have space 2017-07-26
Force Charlie   pull feature 2017-07-26
Pop-Location
Force Charlie   fix args have space 2017-07-26
Force Charlie   pull feature 2017-07-26
Set-Location "$gitdir/secure"$op = Get-Content -ErrorAction Ignore -Path "$gitdir/pointer.json"|ConvertFrom-Json
Force Charlie   fix args have space 2017-07-26
Force Charlie   add process module 2017-08-03
$result = ProcessArgv -FilePath git -ArgumentList $argsif ($result -ne 0) {    exit $result
Force Charlie   pull feature 2017-07-26
}
Force Charlie   fix args have space 2017-07-26
Force Charlie   Rename module 2018-06-20
$aeskey = git --git-dir=`"$gitdir/secure/.git`" config "aes.key"
Force Charlie   fix args have space 2017-07-26
if ($null -eq $aeskey) {    $aeskey = Read-Host "Please input your aes key"}
Force Charlie   pull feature 2017-07-26
if ($null -eq $op) {    Write-Host "Resolve secure file"    git ls-tree -r HEAD|ForEach-Object {        $obj = -Split $_        $file = $obj[3]        $rawfile = "$workdir/$file"        if ($gitfiles.Contains($file)) {            Copy-Item "$gitdir/secure/$file" -Destination "$workdir/$file" -Force
Force Charlie   fix ForEach-Object 2017-07-27
            return ## ForEach-Object need return
Force Charlie   pull feature 2017-07-26
        }        $sdir = Split-Path -Path $rawfile        $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   pull feature 2017-07-26
        }        $ret = Restore-AesFile -File $file -Key $aeskey -Destination $rawfile        if ($ret -ne 0) {
Force Charlie   fix pull 2017-07-27
            Write-Host -ForegroundColor Red "AES Decrypt $file failed"
Force Charlie   pull feature 2017-07-26
        }        else {            Write-Host -ForegroundColor Green "Decrypt $file done"        }    }}else {    Write-Host "trace new secure file"
Force Charlie   fix pull 2017-07-27
    Get-Changeset -Commit $op.sid|ForEach-Object {
Force Charlie   pull feature 2017-07-26
        $file = $_["path"]        if ($_["status"] -eq "D") {            Write-Host "Delete $file"            Remove-Item -Path "$workdir/$file" -Force -ErrorAction Ignore
Force Charlie   fix ForEach-Object 2017-07-27
            return ## ForEach-Object need return
Force Charlie   pull feature 2017-07-26
        }        if ($gitfiles.Contains($file)) {            Remove-Item -Path "$workdir/$file" -Force -ErrorAction Ignore            Copy-Item "$gitdir/secure/$file" -Destination "$workdir/$file" -Force
Force Charlie   fix ForEach-Object 2017-07-27
            return ## ForEach-Object need return
Force Charlie   pull feature 2017-07-26
        }
Force Charlie   fix pull 2017-07-27
        $ret = Restore-AesFile -File "$gitdir/secure/$file" -Key $aeskey -Destination "$workdir/$file"
Force Charlie   pull feature 2017-07-26
        if ($ret -ne 0) {            Write-Host  -ForegroundColor Red "AES decrypt file '$file' throw exception"        }        else {            Write-Host -ForegroundColor Green "Decrypt $file done"        }    }}$scommit = git rev-parse HEAD$message = git log --pretty=format:'%s' -n 1 $scommitSet-Location "$workdir"git add -Aif ($LASTEXITCODE -ne 0) {    exit $LASTEXITCODE}&git commit -m "$message"if ($LASTEXITCODE -ne 0) {    exit $LASTEXITCODE}$wcommit = git rev-parse HEAD$pointer = @{}$pointer["sid"] = $scommit$pointer["wid"] = $wcommitConvertTo-Json -InputObject $pointer|Out-File "$gitdir/pointer.json"Push-Location

搜索帮助