Permalink
Browse files

Added `antigen-restore` command.

This command is used to restore from a snapshot file provided as an argument.
The snapshot file can be generated by the `antigen-snapshot` command.
  • Loading branch information...
1 parent d36c6f9 commit 2c2f91c92d42beda4c872eb839b60ab9f02b6230 @sharat87 sharat87 committed Sep 21, 2012
Showing with 55 additions and 5 deletions.
  1. +37 −3 antigen.zsh
  2. +18 −2 tests/snapshots.t
View
40 antigen.zsh
@@ -358,9 +358,9 @@ antigen-snapshot () {
# <version-hash> <repo-url>
local snapshot_content="$(-antigen-echo-record | sed 's/ .*$//' | sort -u |
while read url; do
- dir="$(-antigen-get-clone-dir "$url")"
- version_hash="$(cd "$dir" && git rev-parse HEAD)"
- echo "$version_hash $dir"
+ local dir="$(-antigen-get-clone-dir "$url")"
+ local version_hash="$(cd "$dir" && git rev-parse HEAD)"
+ echo "$version_hash $url"
done)"
{
@@ -386,6 +386,40 @@ antigen-snapshot () {
}
+antigen-restore () {
+
+ if [[ $# == 0 ]]; then
+ echo 'Please provide a snapshot file to restore from.' >&2
+ return 1
+ fi
+
+ local snapshot_file="$1"
+
+ # TODO: Before doing anything with the snapshot file, verify its checksum.
+ # If it fails, notify this to the user and confirm if restore should
+ # proceed.
+
+ echo -n "Restoring from $snapshot_file..."
+
+ sed -n '1!p' "$snapshot_file" |
+ while read line; do
+
+ local version_hash="${line%% *}"
+ local url="${line##* }"
+ local clone_dir="$(-antigen-get-clone-dir "$url")"
+
+ if [[ ! -d $clone_dir ]]; then
+ git clone "$url" "$clone_dir" > /dev/null
+ fi
+
+ (cd "$clone_dir" && git checkout $version_hash) 2> /dev/null
+
+ done
+
+ echo ' done.'
+ echo 'Please open a new shell to get the restored changes.'
+}
+
antigen-help () {
cat <<EOF
Antigen is a plugin management system for zsh. It makes it easy to grab awesome
View
20 tests/snapshots.t
@@ -18,5 +18,21 @@ See the contents of the snapshot file.
$ cat snapshot-file
version='1'; created_on='*'; checksum='*'; (glob)
- .{40} .*-test-plugin (re)
- .{40} .*-test-plugin2 (re)
+ .{40} .*/test-plugin (re)
+ .{40} .*/test-plugin2 (re)
+
+Reset the antigen's bundle record and run cleanup.
+
+ $ unset _ANTIGEN_BUNDLE_RECORD
+ $ antigen-cleanup --force | grep '^Deleting' | wc -l
+ 2
+
+Restore from the snapshot.
+
+ $ ls dot-antigen/repos | wc -l
+ 0
+ $ antigen-restore snapshot-file
+ Restoring from snapshot-file... done.
+ Please open a new shell to get the restored changes.
+ $ ls dot-antigen/repos | wc -l
+ 2

0 comments on commit 2c2f91c

Please sign in to comment.