From d43f31a79306c2a5a333981f96882c7e24e871f3 Mon Sep 17 00:00:00 2001 From: Shrikant Sharat Date: Sun, 12 Aug 2012 20:15:10 +0530 Subject: [PATCH] Initial implementation of antigen-revert command. Use this command to revert an `antigen-update`. --- antigen.zsh | 22 +++++++++++++++++++ tests/revert-update.t | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 tests/revert-update.t diff --git a/antigen.zsh b/antigen.zsh index 0350ed3..f766bf5 100644 --- a/antigen.zsh +++ b/antigen.zsh @@ -97,16 +97,38 @@ antigen-bundles () { antigen-update () { # Update your bundles, i.e., `git pull` in all the plugin repos. + + date > $ADOTDIR/revert-info + -antigen-echo-record | awk '{print $1}' | sort -u | while read url; do echo "**** Pulling $url" + (dir="$(-antigen-get-clone-dir "$url")" + echo -n "$dir:" + cd "$dir" + git rev-parse HEAD) >> $ADOTDIR/revert-info -antigen-ensure-repo "$url" --update --verbose echo done } +antigen-revert () { + if ! [[ -f $ADOTDIR/revert-info ]]; then + echo 'No revert information available. Cannot revert.' >&2 + fi + + cat $ADOTDIR/revert-info | sed '1!p' | while read line; do + dir="$(echo "$line" | cut -d: -f1)" + git --git-dir="$dir/.git" --work-tree="$dir" \ + checkout "$(echo "$line" | cut -d: -f2)" 2> /dev/null + done + + echo "Reverted to state before running -update on $( + cat $ADOTDIR/revert-info | sed -n 1p)." +} + -antigen-get-clone-dir () { # Takes a repo url and gives out the path that this url needs to be cloned # to. Doesn't actually clone anything. diff --git a/tests/revert-update.t b/tests/revert-update.t new file mode 100644 index 0000000..2974de5 --- /dev/null +++ b/tests/revert-update.t @@ -0,0 +1,61 @@ +Load and test plugin. + + $ antigen-bundle $PLUGIN_DIR + Cloning into '.+?'\.\.\. (re) + done. + $ hehe + hehe + +Save the current HEAD of the plugin. + + $ old_version="$(pg rev-parse HEAD)" + +Modify the plugin. + + $ cat > $PLUGIN_DIR/aliases.zsh < alias hehe='echo hehe, updated' + > EOF + $ pg commit -am 'Updated message' + \[master [a-f0-9]{7}\] Updated message (re) + 1 file changed, 1 insertion(+), 1 deletion(-) + +Save the new HEAD of the plugin. + + $ new_version="$(pg rev-parse HEAD)" + +Define a convenience function to get the current version. + + $ current-version () {(cd dot-antigen/repos/* && git rev-parse HEAD)} + +Confirm we currently have the old version. + + $ [[ $(current-version) == $old_version ]] + +Run antigen's update. + + $ antigen-update + **** Pulling */test-plugin (glob) + From */test-plugin (glob) + ???????..??????? master -> origin/master (glob) + Updating ???????..??????? (glob) + Fast-forward + aliases.zsh | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + Updated from ??????? to ???????. (glob) + ??????? Updated message (glob) + aliases.zsh | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + + +Confirm we have the new version. + + $ [[ $(current-version) == $new_version ]] + +Run update again, with no changes in the origin repo. + + $ antigen-revert + Reverted to state before running -update on *. (glob) + +Confirm we have the old version again. + + $ [[ $(current-version) == $old_version ]] -- 2.0.0