Commit d43f31a79306c2a5a333981f96882c7e24e871f3
1 parent
f76ba3b6c2
Initial implementation of antigen-revert command.
Use this command to revert an `antigen-update`.
Showing 2 changed files with 83 additions and 0 deletions Side-by-side Diff
antigen.zsh
| ... | ... | @@ -97,16 +97,38 @@ antigen-bundles () { |
| 97 | 97 | |
| 98 | 98 | antigen-update () { |
| 99 | 99 | # Update your bundles, i.e., `git pull` in all the plugin repos. |
| 100 | + | |
| 101 | + date > $ADOTDIR/revert-info | |
| 102 | + | |
| 100 | 103 | -antigen-echo-record | |
| 101 | 104 | awk '{print $1}' | |
| 102 | 105 | sort -u | |
| 103 | 106 | while read url; do |
| 104 | 107 | echo "**** Pulling $url" |
| 108 | + (dir="$(-antigen-get-clone-dir "$url")" | |
| 109 | + echo -n "$dir:" | |
| 110 | + cd "$dir" | |
| 111 | + git rev-parse HEAD) >> $ADOTDIR/revert-info | |
| 105 | 112 | -antigen-ensure-repo "$url" --update --verbose |
| 106 | 113 | echo |
| 107 | 114 | done |
| 108 | 115 | } |
| 109 | 116 | |
| 117 | +antigen-revert () { | |
| 118 | + if ! [[ -f $ADOTDIR/revert-info ]]; then | |
| 119 | + echo 'No revert information available. Cannot revert.' >&2 | |
| 120 | + fi | |
| 121 | + | |
| 122 | + cat $ADOTDIR/revert-info | sed '1!p' | while read line; do | |
| 123 | + dir="$(echo "$line" | cut -d: -f1)" | |
| 124 | + git --git-dir="$dir/.git" --work-tree="$dir" \ | |
| 125 | + checkout "$(echo "$line" | cut -d: -f2)" 2> /dev/null | |
| 126 | + done | |
| 127 | + | |
| 128 | + echo "Reverted to state before running -update on $( | |
| 129 | + cat $ADOTDIR/revert-info | sed -n 1p)." | |
| 130 | +} | |
| 131 | + | |
| 110 | 132 | -antigen-get-clone-dir () { |
| 111 | 133 | # Takes a repo url and gives out the path that this url needs to be cloned |
| 112 | 134 | # to. Doesn't actually clone anything. |
tests/revert-update.t
| ... | ... | @@ -0,0 +1,61 @@ |
| 1 | +Load and test plugin. | |
| 2 | + | |
| 3 | + $ antigen-bundle $PLUGIN_DIR | |
| 4 | + Cloning into '.+?'\.\.\. (re) | |
| 5 | + done. | |
| 6 | + $ hehe | |
| 7 | + hehe | |
| 8 | + | |
| 9 | +Save the current HEAD of the plugin. | |
| 10 | + | |
| 11 | + $ old_version="$(pg rev-parse HEAD)" | |
| 12 | + | |
| 13 | +Modify the plugin. | |
| 14 | + | |
| 15 | + $ cat > $PLUGIN_DIR/aliases.zsh <<EOF | |
| 16 | + > alias hehe='echo hehe, updated' | |
| 17 | + > EOF | |
| 18 | + $ pg commit -am 'Updated message' | |
| 19 | + \[master [a-f0-9]{7}\] Updated message (re) | |
| 20 | + 1 file changed, 1 insertion(+), 1 deletion(-) | |
| 21 | + | |
| 22 | +Save the new HEAD of the plugin. | |
| 23 | + | |
| 24 | + $ new_version="$(pg rev-parse HEAD)" | |
| 25 | + | |
| 26 | +Define a convenience function to get the current version. | |
| 27 | + | |
| 28 | + $ current-version () {(cd dot-antigen/repos/* && git rev-parse HEAD)} | |
| 29 | + | |
| 30 | +Confirm we currently have the old version. | |
| 31 | + | |
| 32 | + $ [[ $(current-version) == $old_version ]] | |
| 33 | + | |
| 34 | +Run antigen's update. | |
| 35 | + | |
| 36 | + $ antigen-update | |
| 37 | + **** Pulling */test-plugin (glob) | |
| 38 | + From */test-plugin (glob) | |
| 39 | + ???????..??????? master -> origin/master (glob) | |
| 40 | + Updating ???????..??????? (glob) | |
| 41 | + Fast-forward | |
| 42 | + aliases.zsh | 2 +- | |
| 43 | + 1 file changed, 1 insertion(+), 1 deletion(-) | |
| 44 | + Updated from ??????? to ???????. (glob) | |
| 45 | + ??????? Updated message (glob) | |
| 46 | + aliases.zsh | 2 +- | |
| 47 | + 1 file changed, 1 insertion(+), 1 deletion(-) | |
| 48 | + | |
| 49 | + | |
| 50 | +Confirm we have the new version. | |
| 51 | + | |
| 52 | + $ [[ $(current-version) == $new_version ]] | |
| 53 | + | |
| 54 | +Run update again, with no changes in the origin repo. | |
| 55 | + | |
| 56 | + $ antigen-revert | |
| 57 | + Reverted to state before running -update on *. (glob) | |
| 58 | + | |
| 59 | +Confirm we have the old version again. | |
| 60 | + | |
| 61 | + $ [[ $(current-version) == $old_version ]] |