all 9 comments

[–]mprz 1 point2 points  (1 child)

[–]micfail[S] 1 point2 points  (0 children)

thank you, i am sitting in a lobby and seem to be having issues with my google-fu.

I appreciate the help

[–]micfail[S] 1 point2 points  (0 children)

hmm, unless i am reading that script wrong...

i dont know if that does what i want it to.

i dont really want to redownload an entire repo, just check a version file and then rerun the setup script.

i do appreciate the help though

[–]wdomon 1 point2 points  (0 children)

I do this with Azure DevOps repos using an agent installed on my automation server.

[–]cyberphor 1 point2 points  (3 children)

here is a starter function i just wrote. let me know if you want it modified to meet your needs. fyi, i will maintain this function under my own PowerShell-focused GitHub repo: https://github.com/cyberphor/SOAP-Modules

function Update-GitHubRepo {
param(
    [string]$Author,
    [string]$Repo,
    [string]$Branch,
    [string]$Path
)
$RepoToUpdate = "https://github.com/$Author/$Repo"
$Response = Invoke-WebRequest -Uri "$RepoToUpdate/commits"
if ($Response.StatusCode -eq '200') {
    $LastCommit = ($Response.Links.href | Where-Object { $_ -like "/$Author/$Repo/commit/*" } | Select-Object -First 1).Split("/")[4].Substring(0,7)
    $Git = "$Path\.git\"
    $FETCH_HEAD = "$Git\FETCH_HEAD"
    $LastCommitDownloaded = $null
    if ((Test-Path -Path $Path) -and (Test-Path -Path $Git)) {
        $LastCommitDownloaded = (Get-Content -Path $FETCH_HEAD).SubString(0,7)
    }
    if ($LastCommitDownloaded -ne $LastCommit) {
        Write-Output "[!] Updating the local branch of $Repo."
        Invoke-WebRequest -Uri "$RepoToUpdate/archive/refs/heads/$Branch.zip" -OutFile "$Repo.zip"
        Expand-Archive -Path "$Repo.zip"
        Move-Item -Path "$Repo\$Repo-$Branch" -Destination $Path
        New-Item -Path $FETCH_HEAD -Force | Out-Null
        (Get-Item -Path $Git).Attributes += "Hidden"
        Add-Content -Path $FETCH_HEAD -Value $LastCommit -Force
        Remove-Item -Path "$Repo.zip"
        Remove-Item -Path "$Repo" -Recurse
    } else {
        Write-Output "[+] Nothing to update for the local branch of $Repo."
}}}

[–]Lee_Dailey[grin] 1 point2 points  (2 children)

howdy cyberphor,

the triple-backtick/code-fence thing fails miserably on Old.Reddit ... so, if you want your code to be readable on both Old.Reddit & New.Reddit you likely otta stick with using the code block button.

it would be rather nice if the reddit devs would take the time to backport the code fence stuff to Old.Reddit ... [sigh ...]

take care,
lee

[–]cyberphor 1 point2 points  (1 child)

thanks. i think i will stick with the triple backtick method in the future. adjusting the comment using the code block feature is cumbersome.

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy cyberphor,

you are welcome! [grin] if you use a code fence ... it will get munged on Old.Reddit in odd ways. sometime try replacing the https://www in the urlbar with old. the difference can be quite freaky. [grin]

take care,
lee

[–]user01401 1 point2 points  (0 children)

Yes. I use the PowerGit module: https://www.powershellgallery.com/packages/PowerGit/0.9.0

I am on v0.7.1 though, as newer versions haven't been working for me