-
-
Save YourFriendCaspian/cf488dc6e24eb280db0b77ee60480e44 to your computer and use it in GitHub Desktop.
Powershell to sync and push to remote git repository via Windows Scheduled Tasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Hack to workaround the Powershell Console popup running on a Windows Scheduled Task | |
' Powershell limitations: https://github.com/PowerShell/PowerShell/issues/3028 | |
' | |
' Add this file in the same git root directory as the sync.ps1 | |
' | |
Dim shell,command | |
Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject") | |
Dim sScriptDir : sScriptDir = oFSO.GetParentFolderName(WScript.ScriptFullName) | |
command = "powershell.exe -nologo -File " & sScriptDir & "\sync.ps1" | |
Set shell = CreateObject("WScript.Shell") | |
shell.Run command,0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function GitCommitAndPush { | |
$dateString = Get-Date -UFormat "%Y-%m-%d %H:%M:%S" | |
git add . | |
git commit -q -m "$($dateString)" | |
git push -q | |
} | |
function GitPull { | |
git pull | |
} | |
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition | |
Set-Location -Path $scriptPath | |
GitPull | |
if(git status --porcelain |Where {$_ -match '^\?\?'}){ | |
# untracked files exist | |
GitCommitAndPush | |
Exit 0 | |
} | |
elseif(git status --porcelain |Where {$_ -notmatch '^\?\?'}) { | |
# uncommitted changes | |
GitCommitAndPush | |
Exit 0 | |
} | |
else { | |
# tree is clean | |
Exit 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment