Commit 843297b2062084271496e3998623e446c397b832
1 parent
2e6d0c4163
Initial implementation of --branch.
The `antigen-bundle` command takes a `--branch` keyword-only argument that specified the branch of the repo to be used for this bundle. Alpha implementation. Needs more testing.
Showing 1 changed file with 34 additions and 10 deletions Side-by-side Diff
antigen.zsh
| ... | ... | @@ -8,11 +8,14 @@ local _ANTIGEN_BUNDLE_RECORD="" |
| 8 | 8 | |
| 9 | 9 | # Syntaxes |
| 10 | 10 | # antigen-bundle <url> [<loc>=/] |
| 11 | +# Keyword only arguments: | |
| 12 | +# branch - The branch of the repo to use for this bundle. | |
| 11 | 13 | antigen-bundle () { |
| 12 | 14 | |
| 13 | 15 | # Bundle spec arguments' default values. |
| 14 | 16 | local url="$ANTIGEN_DEFAULT_REPO_URL" |
| 15 | 17 | local loc=/ |
| 18 | + local branch=- | |
| 16 | 19 | local btype=plugin |
| 17 | 20 | |
| 18 | 21 | # Set spec values based on the positional arguments. |
| ... | ... | @@ -48,11 +51,11 @@ antigen-bundle () { |
| 48 | 51 | fi |
| 49 | 52 | |
| 50 | 53 | # Add it to the record. |
| 51 | - _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$url $loc $btype" | |
| 54 | + _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$url $loc $btype $branch" | |
| 52 | 55 | |
| 53 | - -antigen-ensure-repo "$url" | |
| 56 | + -antigen-ensure-repo "$url" "$branch" | |
| 54 | 57 | |
| 55 | - -antigen-load "$url" "$loc" "$btype" | |
| 58 | + -antigen-load "$url" "$loc" "$btype" "$branch" | |
| 56 | 59 | |
| 57 | 60 | } |
| 58 | 61 | |
| ... | ... | @@ -81,11 +84,21 @@ antigen-update () { |
| 81 | 84 | # Takes a repo url and gives out the path that this url needs to be cloned |
| 82 | 85 | # to. Doesn't actually clone anything. |
| 83 | 86 | # TODO: Memoize? |
| 87 | + local url="$1" | |
| 88 | + local branch="$2" | |
| 84 | 89 | echo -n $ADOTDIR/repos/ |
| 85 | - echo "$1" | sed \ | |
| 90 | + | |
| 91 | + local branched_url="$url" | |
| 92 | + | |
| 93 | + if [[ "$branch" != - ]]; then | |
| 94 | + branched_url="$branched_url|$branch" | |
| 95 | + fi | |
| 96 | + | |
| 97 | + echo "$branched_url" | sed \ | |
| 86 | 98 | -e 's/\.git$//' \ |
| 87 | 99 | -e 's./.-SLASH-.g' \ |
| 88 | - -e 's.:.-COLON-.g' | |
| 100 | + -e 's.:.-COLON-.g' \ | |
| 101 | + -e 's.|.-PIPE-.g' | |
| 89 | 102 | } |
| 90 | 103 | |
| 91 | 104 | -antigen-get-clone-url () { |
| ... | ... | @@ -96,7 +109,8 @@ antigen-update () { |
| 96 | 109 | -e "s:^$ADOTDIR/repos/::" \ |
| 97 | 110 | -e 's/$/.git/' \ |
| 98 | 111 | -e 's.-SLASH-./.g' \ |
| 99 | - -e 's.-COLON-.:.g' | |
| 112 | + -e 's.-COLON-.:.g' \ | |
| 113 | + -e 's.-PIPE-.|.g' | |
| 100 | 114 | } |
| 101 | 115 | |
| 102 | 116 | -antigen-ensure-repo () { |
| ... | ... | @@ -108,7 +122,8 @@ antigen-update () { |
| 108 | 122 | fi |
| 109 | 123 | |
| 110 | 124 | local url="$1" |
| 111 | - local clone_dir="$(-antigen-get-clone-dir $url)" | |
| 125 | + local branch="$2" | |
| 126 | + local clone_dir="$(-antigen-get-clone-dir $url $branch)" | |
| 112 | 127 | |
| 113 | 128 | if [[ ! -d $clone_dir ]]; then |
| 114 | 129 | git clone "$url" "$clone_dir" |
| ... | ... | @@ -116,13 +131,21 @@ antigen-update () { |
| 116 | 131 | git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" pull |
| 117 | 132 | fi |
| 118 | 133 | |
| 134 | + if [[ "$branch" != - ]]; then | |
| 135 | + git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ | |
| 136 | + checkout "$branch" | |
| 137 | + fi | |
| 138 | + | |
| 119 | 139 | } |
| 120 | 140 | |
| 121 | 141 | -antigen-load () { |
| 122 | 142 | |
| 123 | 143 | local url="$1" |
| 124 | - local location="$(-antigen-get-clone-dir "$url")/$2" | |
| 144 | + local loc="$2" | |
| 125 | 145 | local btype="$3" |
| 146 | + local branch="$4" | |
| 147 | + | |
| 148 | + local location="$(-antigen-get-clone-dir "$url" "$branch")/$loc" | |
| 126 | 149 | |
| 127 | 150 | if [[ $btype == theme ]]; then |
| 128 | 151 | |
| ... | ... | @@ -165,7 +188,7 @@ antigen-cleanup () { |
| 165 | 188 | |
| 166 | 189 | # Find directores in ADOTDIR/repos, that are not in the bundles record. |
| 167 | 190 | local unused_clones="$(comm -13 \ |
| 168 | - <(-antigen-echo-record | awk '{print $1}' | sort -u) \ | |
| 191 | + <(-antigen-echo-record | awk '{print $1 "|" $4}' | sort -u) \ | |
| 169 | 192 | <(ls "$ADOTDIR/repos" | while read line; do |
| 170 | 193 | -antigen-get-clone-url "$line" |
| 171 | 194 | done))" |
| ... | ... | @@ -176,7 +199,8 @@ antigen-cleanup () { |
| 176 | 199 | fi |
| 177 | 200 | |
| 178 | 201 | echo 'You have clones for the following repos, but are not used.' |
| 179 | - echo "$unused_clones" | sed 's/^/ /' | |
| 202 | + echo "$unused_clones" \ | |
| 203 | + | sed -e 's/^/ /' -e 's/|/, branch /' | |
| 180 | 204 | |
| 181 | 205 | echo -n '\nDelete them all? [y/N] ' |
| 182 | 206 | if read -q; then |