From d36c6f93d8dde634a1232495944a6f6adbce2ea4 Mon Sep 17 00:00:00 2001 From: Shrikant Sharat Date: Fri, 21 Sep 2012 17:17:09 +0530 Subject: [PATCH] Implemented `antigen-snapshot` command. Creates a snapshot file with some basic metadata information and pairs of repo urls and their version hashes. Tests included. --- antigen.zsh | 37 +++++++++++++++++++++++++++++++++++++ tests/snapshots.t | 22 ++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 tests/snapshots.t diff --git a/antigen.zsh b/antigen.zsh index c71d4d1..87af785 100644 --- a/antigen.zsh +++ b/antigen.zsh @@ -349,6 +349,43 @@ antigen-list () { fi } +antigen-snapshot () { + + local snapshot_file="${1:-antigen-shapshot}" + + # The snapshot content lines are pairs of repo-url and git version hash, in + # the form: + # + 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" + done)" + + { + # The first line in the snapshot file is for metadata, in the form: + # key='value'; key='value'; key='value'; + # Where `key`s are valid shell variable names. + + # Snapshot version. Has no relation to antigen version. If the snapshot + # file format changes, this number can be incremented. + echo -n "version='1';" + + # Snapshot creation date+time. + echo -n " created_on='$(date)';" + + # Add a checksum with the md5 checksum of all the snapshot lines. + local checksum="$(echo "$snapshot_content" | md5sum)" + echo -n " checksum='${checksum%% *}';" + + # A newline after the metadata and then the snapshot lines. + echo "\n$snapshot_content" + + } > "$snapshot_file" + +} + antigen-help () { cat <