Fix: Install - port to powershell

This commit is contained in:
alstjr7375 2022-04-23 00:13:55 +09:00
parent 5216110ba5
commit a021cdf509
2 changed files with 35 additions and 27 deletions

View file

@ -727,7 +727,8 @@ function Apply-CustomFile() {
[string] $otherCustomPath = "" [string] $otherCustomPath = ""
) )
$local:gitDir = "${profilePath}\chrome\.git" $local:leptonDir = "${profilePath}\chrome"
$local:gitDir = "${leptonDir}\.git"
if ( Test-Path -Path "${customPath}" -PathType leaf ) { if ( Test-Path -Path "${customPath}" -PathType leaf ) {
$global:customFileApplied = $true $global:customFileApplied = $true
@ -737,10 +738,10 @@ function Apply-CustomFile() {
if ( "${customReset}" -eq $true ) { if ( "${customReset}" -eq $true ) {
if ( "${targetPath}" -like "*user.js" ) { if ( "${targetPath}" -like "*user.js" ) {
Copy-Item -Path "${customFile}" -Destination "${targetPath}" -Force Copy-Item -Path "${leptonDir}\user.js" -Destination "${targetPath}" -Force
} }
else { else {
git --git-dir "${gitDir}" checkout HEAD -- "${targetPath}" git --git-dir "${gitDir}" --work-tree "${leptonDir}" checkout HEAD -- "${targetPath}"
} }
} }
if ( "${customAppend}" -eq $true ) { if ( "${customAppend}" -eq $true ) {
@ -875,26 +876,30 @@ function Install-Profile() {
#** Update ********************************************************************* #** Update *********************************************************************
function Stash-File() { function Stash-File() {
Param ( Param (
[Parameter(Position=0)] [Parameter(Mandatory=$true, Position=0)]
[string] $gitDir = ".git" [string] $leptonDir,
[Parameter(Mandatory=$true, Position=1)]
[string] $gitDir
) )
if ( "$(git --git-dir "${gitDir}" diff --stat)" -ne '' ) { if ( "$(git --git-dir "${gitDir}" --work-tree "${leptonDir}" diff --stat)" -ne '' ) {
git --git-dir "${gitDir}" checkout stash git --git-dir "${gitDir}" --work-tree "${leptonDir}" checkout stash
return $true return $true
} }
return $false return $false
} }
function Restore-File() { function Restore-File() {
Param ( Param (
[Parameter(Position=0)] [Parameter(Mandatory=$true, Position=0)]
[string] $gitDir = ".git", [string] $leptonDir,
[Parameter(Position=1)] [Parameter(Mandatory=$true, Position=1)]
[string] $gitDir,
[Parameter(Position=2)]
[switch] $gitDirty = $false [switch] $gitDirty = $false
) )
if ( "${gitDirty}" -eq $true ) { if ( "${gitDirty}" -eq $true ) {
git --git-dir "${gitDir}" checkout stash pop --quiet git --git-dir "${gitDir}" --work-tree "${leptonDir}" checkout stash pop --quiet
} }
} }
@ -910,14 +915,15 @@ function Update-Profile() {
$local:Branch = $LEPTONINFO["${section}"]["Branch"] $local:Branch = $LEPTONINFO["${section}"]["Branch"]
$local:Path = $LEPTONINFO["${section}"]["Path"] $local:Path = $LEPTONINFO["${section}"]["Path"]
$local:LEPTONGITPATH="${Path}\chrome\.git" $local:leptonDir = "${Path}\chrome"
$local:gitDir = "${leptonDir}\.git"
if ( "${Type}" -eq "Git" ) { if ( "${Type}" -eq "Git" ) {
$local:gitDirty = $(Stash-File "${LEPTONGITPATH}") $local:gitDirty = $(Stash-File "${leptonDir}" "${gitDir}")
git --git-dir "${LEPTONGITPATH}" checkout "${Branch}" git --git-dir "${gitDir}" --work-tree "${leptonDir}" checkout "${Branch}"
git --git-dir "${LEPTONGITPATH}" pull --no-edit git --git-dir "${gitDir}" --work-tree "${leptonDir}" pull --no-edit
Restore-File "${LEPTONGITPATH}" $gitDirty Restore-File "${leptonDir}" "${gitDir}" $gitDirty
} }
elseif ( "${Type}" -eq "Local" -or "${Type}" -eq "Release" ) { elseif ( "${Type}" -eq "Local" -or "${Type}" -eq "Release" ) {
Check-ChromeExist Check-ChromeExist
@ -929,11 +935,11 @@ function Update-Profile() {
if ( "${Branch}" -eq $null ) { if ( "${Branch}" -eq $null ) {
$Branch = "${leptonBranch}" $Branch = "${leptonBranch}"
} }
git --git-dir "${LEPTONGITPATH}" checkout "${Branch}" git --git-dir "${gitDir}" --work-tree "${leptonDir}" checkout "${Branch}"
if ( "${Type}" -eq "Release" ) { if ( "${Type}" -eq "Release" ) {
$local:Ver=$(git --git-dir "${LEPTONINFOFILE}" describe --tags --abbrev=0) $local:Ver=$(git --git-dir "${gitDir}" describe --tags --abbrev=0)
git --git-dir "${LEPTONGITPATH}" checkout "tags/${Ver}" git --git-dir "${gitDir}" --work-tree "${leptonDir}" checkout "tags/${Ver}"
} }
Clean-Lepton Clean-Lepton

View file

@ -843,16 +843,18 @@ install_profile() {
#** Update ********************************************************************* #** Update *********************************************************************
file_stash() { file_stash() {
local profilePath=$1 local leptonDir=$1
if [[ $(git --git-dir "${profilePath}/.git" --work-tree "${profilePath}/chrome" diff --stat) != '' ]]; then local gitDir=$2
git --git-dir "${profilePath}/chrome/.git" --work-tree "${profilePath}/chrome" stash if [[ $(git --git-dir "${gitDir}" --work-tree "${leptonDir}" diff --stat) != '' ]]; then
git --git-dir "${gitDir}" --work-tree "${leptonDir}" stash
fi fi
} }
file_restore() { file_restore() {
local profilePath=$1 local leptonDir=$1
local gitDirty=$2 local gitDir=$2
local gitDirty=$3
if [ -n "${gitDirty}" ]; then if [ -n "${gitDirty}" ]; then
git --git-dir "${profilePath}/chrome/.git" --work-tree "${profilePath}/chrome" stash pop --quiet git --git-dir "${gitDir}" --work-tree "${leptonDir}" stash pop --quiet
fi fi
} }
@ -870,12 +872,12 @@ update_profile() {
local leptonDir="${Path}/chrome" local leptonDir="${Path}/chrome"
local gitDir="${leptonDir}/.git" local gitDir="${leptonDir}/.git"
if [ "${Type}" == "Git" ]; then if [ "${Type}" == "Git" ]; then
local gitDirty="$(file_stash ${gitDir})" local gitDirty=$(file_stash "${leptonDir}" "${gitDir}")
git --git-dir "${gitDir}" --work-tree "${leptonDir}" checkout "${Branch}" git --git-dir "${gitDir}" --work-tree "${leptonDir}" checkout "${Branch}"
git --git-dir "${gitDir}" --work-tree "${leptonDir}" pull --no-edit git --git-dir "${gitDir}" --work-tree "${leptonDir}" pull --no-edit
file_restore "${Path}" "${gitDirty}" file_restore "${leptonDir}" "${gitDir}" "${gitDirty}"
elif [ "${Type}" == "Local" ] || [ "${Type}" == "Release" ]; then elif [ "${Type}" == "Local" ] || [ "${Type}" == "Release" ]; then
check_chrome_exist check_chrome_exist
clone_lepton clone_lepton