From 94ae0cc92ada5372715295cb6069e29f2afffa8f Mon Sep 17 00:00:00 2001 From: Simon Hartcher Date: Sat, 4 Apr 2015 14:22:23 +1100 Subject: [PATCH 1/4] Changed scoop update to use git for updating self --- libexec/scoop-status.ps1 | 9 ++++---- libexec/scoop-update.ps1 | 48 +++++++++++++++++----------------------- 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/libexec/scoop-status.ps1 b/libexec/scoop-status.ps1 index 8c893b2e3..7122807ca 100644 --- a/libexec/scoop-status.ps1 +++ b/libexec/scoop-status.ps1 @@ -18,11 +18,12 @@ function timeago($when) { } # check when scoop was last updated -$timestamp = "$(versiondir 'scoop' 'current')\last_updated" -if(test-path $timestamp) { - $last_update = [io.file]::getlastwritetime((resolve-path $timestamp)) - "scoop was last updated $(timeago($last_update))" +git fetch origin +$commits = $(git log HEAD..origin/master --oneline) +if($commits) { + "scoop is out of date. run scoop update to get the latest changes." } +else { "scoop is up-to-date."} $failed = @() $old = @() diff --git a/libexec/scoop-update.ps1 b/libexec/scoop-update.ps1 index 08ee41a66..e5bfe991d 100644 --- a/libexec/scoop-update.ps1 +++ b/libexec/scoop-update.ps1 @@ -26,42 +26,34 @@ $force = $opt.f -or $opt.force $use_cache = !($opt.k -or $opt.'no-cache') function update_scoop() { - $tempdir = versiondir 'scoop' 'update' - $currentdir = versiondir 'scoop' 'current' + # check for git + $git = try { gcm git -ea stop } catch { $null } + if(!$git) { abort "scoop uses git to update itself. run 'scoop install git'." } - if(test-path $tempdir) { - try { rm -r $tempdir -ea stop -force } catch { abort "couldn't remove $tempdir`: it may be in use" } + "updating scoop..." + $currentdir = fullpath $(versiondir 'scoop' 'current') + if(!(test-path "$currentdir\.git")) { + # remove non-git scoop + rm -r -force $currentdir -ea stop + + # get git scoop + # todo: pull the address out into a variable somewhere + git clone "http://github.com/lukesampson/scoop" $currentdir + } + else { + pushd $currentdir + git pull -q + popd } - $tempdir = ensure $tempdir - $currentdir = fullpath $currentdir - $zipurl = 'https://github.com/lukesampson/scoop/archive/master.zip' - $zipfile = "$tempdir\scoop.zip" - echo 'downloading...' - dl $zipurl $zipfile - - echo 'extracting...' - unzip $zipfile $tempdir - rm $zipfile - - echo 'replacing files...' - $null = robocopy "$tempdir\scoop-master" $currentdir /mir /njh /njs /nfl /ndl - rm -r -force $tempdir -ea stop - - $null > "$currentdir\last_updated" # save update timestamp ensure_scoop_in_path - shim "$currentdir\bin\scoop.ps1" $false @(buckets) | % { "updating $_ bucket..." - $git = try { gcm git -ea stop } catch { $null } - if(!$git) { warn "git is required for buckets. run 'scoop install git'." } - else { - pushd (bucketdir $_) - git pull -q - popd - } + pushd (bucketdir $_) + git pull -q + popd } success 'scoop was updated successfully!' } From 735ee1757196ef6f15e80679b59bc8972dbfcf2d Mon Sep 17 00:00:00 2001 From: Simon Hartcher Date: Sat, 4 Apr 2015 14:48:41 +1100 Subject: [PATCH 2/4] Fixed status command. Added support for custom repo/branch. --- libexec/scoop-status.ps1 | 20 ++++++++++++++++---- libexec/scoop-update.ps1 | 16 ++++++++++++++-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/libexec/scoop-status.ps1 b/libexec/scoop-status.ps1 index 7122807ca..38c90a817 100644 --- a/libexec/scoop-status.ps1 +++ b/libexec/scoop-status.ps1 @@ -17,10 +17,22 @@ function timeago($when) { return "$([int]$diff.totalseconds) seconds ago" } -# check when scoop was last updated -git fetch origin -$commits = $(git log HEAD..origin/master --oneline) -if($commits) { +# check if scoop needs updating +$currentdir = fullpath $(versiondir 'scoop' 'current') +$needs_update = $false + +if(test-path "$currentdir\.git") { + pushd $currentdir + git fetch origin + $commits = $(git log "HEAD..origin/$(scoop config SCOOP_BRANCH)" --oneline) + if($commits) { $needs_update = $true } + popd +} +else { + $needs_update = $true +} + +if($needs_update) { "scoop is out of date. run scoop update to get the latest changes." } else { "scoop is up-to-date."} diff --git a/libexec/scoop-update.ps1 b/libexec/scoop-update.ps1 index e5bfe991d..9a9fae934 100644 --- a/libexec/scoop-update.ps1 +++ b/libexec/scoop-update.ps1 @@ -33,12 +33,24 @@ function update_scoop() { "updating scoop..." $currentdir = fullpath $(versiondir 'scoop' 'current') if(!(test-path "$currentdir\.git")) { + # load config + $repo = $(scoop config SCOOP_REPO) + if(!$repo) { + $repo = "http://github.com/lukesampson/scoop" + scoop config SCOOP_REPO "$repo" + } + + $branch = $(scoop config SCOOP_BRANCH) + if(!$branch) { + $branch = "master" + scoop config SCOOP_BRANCH "$branch" + } + # remove non-git scoop rm -r -force $currentdir -ea stop # get git scoop - # todo: pull the address out into a variable somewhere - git clone "http://github.com/lukesampson/scoop" $currentdir + git clone -q $repo --branch $branch --single-branch $currentdir } else { pushd $currentdir From ed3972ee759412dcf38dfdcdf96cf3ebda95541d Mon Sep 17 00:00:00 2001 From: Simon Hartcher Date: Sat, 4 Apr 2015 14:58:04 +1100 Subject: [PATCH 3/4] Removed unused timestamp code --- bin/install.ps1 | 2 -- libexec/scoop-status.ps1 | 9 --------- 2 files changed, 11 deletions(-) diff --git a/bin/install.ps1 b/bin/install.ps1 index a78d53412..f114f6304 100644 --- a/bin/install.ps1 +++ b/bin/install.ps1 @@ -29,8 +29,6 @@ cp "$dir\_scoop_extract\scoop-master\*" $dir -r -force rm "$dir\_scoop_extract" -r -force rm $zipfile -$null > "$dir\last_updated" # save install timestamp - echo 'creating shim...' shim "$dir\bin\scoop.ps1" $false diff --git a/libexec/scoop-status.ps1 b/libexec/scoop-status.ps1 index 38c90a817..49de57ea8 100644 --- a/libexec/scoop-status.ps1 +++ b/libexec/scoop-status.ps1 @@ -8,15 +8,6 @@ . "$psscriptroot\..\lib\depends.ps1" . "$psscriptroot\..\lib\config.ps1" -function timeago($when) { - $diff = [datetime]::now - $last_update - - if($diff.totaldays -gt 2) { return "$([int]$diff.totaldays) days ago" } - if($diff.totalhours -gt 2) { return "$([int]$diff.totalhours) hours ago" } - if($diff.totalminutes -gt 2) { return "$([int]$diff.totalminutes) minutes ago" } - return "$([int]$diff.totalseconds) seconds ago" -} - # check if scoop needs updating $currentdir = fullpath $(versiondir 'scoop' 'current') $needs_update = $false From 3e0b5293bcc38e5b950cbe819c3d09be72e46944 Mon Sep 17 00:00:00 2001 From: Simon Hartcher Date: Sat, 4 Apr 2015 15:45:52 +1100 Subject: [PATCH 4/4] Changed scoop-status to git fetch quietly --- libexec/scoop-status.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/scoop-status.ps1 b/libexec/scoop-status.ps1 index 49de57ea8..ff6354eda 100644 --- a/libexec/scoop-status.ps1 +++ b/libexec/scoop-status.ps1 @@ -14,7 +14,7 @@ $needs_update = $false if(test-path "$currentdir\.git") { pushd $currentdir - git fetch origin + git fetch -q origin $commits = $(git log "HEAD..origin/$(scoop config SCOOP_BRANCH)" --oneline) if($commits) { $needs_update = $true } popd