GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — git-friendly/pull at main · git-friendly/git-friendly Expand file tree/ Copy pathpullMore file actions executable file ·176 lines (154 loc) · 5.31 KB / Copy pathpullFile metadata and controlsexecutable file ·176 lines (154 loc) · 5.31 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 #!/bin/bash # # Usage: pull # # Pulls remote changes using rebase & tries to rebundle, # safely stashing and re-applying your local changes, if any # # Abort if this isn't a git repository git rev-parse --is-inside-work-tree >/dev/null || exit $? # Colors color_error="$(tput sgr 0 1)$(tput setaf 1)" color_reset="$(tput sgr0)" # Current working dir and repo base dir current_dir="$(pwd)" base_dir=$(git rev-parse --show-cdup) # Test whether a command exists # $1 - cmd to test cmd_exists() { command -v "$1" >/dev/null 2>&1 } # Test whether a config variable is switched on # $1 - value; empty, 0 and false all count as off is_enabled() { case "$1" in '' | 0 | false) return 1 ;; esac } # Test whether a file exists # $1 - file to test file_exists() { if [[ -r "./$base_dir$1" ]]; then return 0 fi return 1 } # Go to directory of changed file # $1 - filename change_dir() { file=$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD | grep "$1") if [[ -e "./$base_dir$file" ]]; then cd "$(dirname "./$base_dir$file")" || return 1 return 0 fi return 1 } # Go back to reset_dir() { cd "$current_dir" || return 1 } # Test whether a file has changed since the pre-pull HEAD. # $1 - filename has_changed() { # ORIG_HEAD is the value of HEAD before the pull. changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD 2>/dev/null)" echo "$changed_files" | grep --quiet "$1" } branch=$(git branch --show-current) || exit $? if [ -z "$branch" ]; then echo "${color_error}❌ You're not on a branch (detached HEAD). Check out a branch first.${color_reset}" >&2 exit 1 fi default_remote="origin" remote=$(git config "branch.${branch}.remote" || echo "$default_remote") remote_branch=$( (git config "branch.${branch}.merge" || echo "refs/heads/$branch") | cut -d/ -f3-) # Fetch all branches (and prune stale ones) so remote-tracking refs # stay complete — `git pull <remote> <branch>` alone only updates the # one ref you name. Skip submodules here; the recursive pull below owns # submodule updates, so recursing now just double-fetches them. echo "🚀 Fetching from $remote..." git fetch --prune --no-recurse-submodules --jobs=10 "$remote" || exit $? # Pull, using rebase if configured if ! is_enabled "$GIT_FRIENDLY_NO_REBASE_ON_PULL"; then rebase="--rebase" else rebase="--no-rebase" fi # --autostash lets git shelve and restore local changes itself. It beats a # manual stash/pop around the pull: when a rebase stops on a conflict git # holds the changes back until `git rebase --continue`, instead of popping # them into a half-rebased tree. Note it does not stash untracked files. git pull $rebase --autostash --recurse-submodules --jobs=10 $remote $remote_branch || exit $? # Bundle em if you got em! if ! is_enabled "$GIT_FRIENDLY_NO_BUNDLE"; then if cmd_exists 'bundle' && (has_changed 'Gemfile' || has_changed 'gems.rb'); then echo echo '⚔ Bundling gems...' change_dir 'Gemfile' || change_dir 'gems.rb' bundle check >/dev/null 2>&1 || bundle install reset_dir fi fi # JS packages — each block fires when its own lockfile is present; # npm is the fallback used only when no JS lockfile exists at all. has_js_lockfile() { file_exists 'yarn.lock' || file_exists 'pnpm-lock.yaml' \ || file_exists 'bun.lock' || file_exists 'bun.lockb' } if ! is_enabled "$GIT_FRIENDLY_NO_YARN" && cmd_exists 'yarn' \ && file_exists 'yarn.lock' && (has_changed 'yarn.lock' || has_changed 'package.json'); then change_dir 'yarn.lock' || change_dir 'package.json' echo echo '⚔ Installing packages with yarn...' yarn install reset_dir fi if ! is_enabled "$GIT_FRIENDLY_NO_PNPM" && cmd_exists 'pnpm' \ && file_exists 'pnpm-lock.yaml' && (has_changed 'pnpm-lock.yaml' || has_changed 'package.json'); then change_dir 'pnpm-lock.yaml' || change_dir 'package.json' echo echo '⚔ Installing packages with pnpm...' pnpm install reset_dir fi if ! is_enabled "$GIT_FRIENDLY_NO_BUN" && cmd_exists 'bun' \ && (file_exists 'bun.lock' || file_exists 'bun.lockb') \ && (has_changed 'bun.lock' || has_changed 'bun.lockb' || has_changed 'package.json'); then change_dir 'bun.lock' || change_dir 'bun.lockb' || change_dir 'package.json' echo echo '⚔ Installing packages with bun...' bun install reset_dir fi if ! is_enabled "$GIT_FRIENDLY_NO_NPM" && cmd_exists 'npm' \ && has_changed 'package.json' && ! has_js_lockfile; then change_dir 'package.json' echo echo '⚔ Installing packages with npm...' npm install reset_dir fi # Install uv packages (Python). Anchored on uv.lock so we never run uv # against a non-uv pyproject.toml (poetry/hatch/pip-tools also use one). if ! is_enabled "$GIT_FRIENDLY_NO_UV" && cmd_exists 'uv' \ && file_exists 'uv.lock' && (has_changed 'uv.lock' || has_changed 'pyproject.toml'); then change_dir 'uv.lock' || change_dir 'pyproject.toml' echo echo '⚔ Installing packages with uv...' uv sync reset_dir fi # Install Composer packages if ! is_enabled "$GIT_FRIENDLY_NO_COMPOSER"; then if has_changed 'composer.lock'; then change_dir 'composer.lock' if cmd_exists 'composer' || (cmd_exists 'php' && [ -f ./composer.phar ]); then echo echo '⚔ Installing Composer packages...' [ -f ./composer.phar ] && php composer.phar install || composer install fi reset_dir fi fi echo "🦄 Done" exit 0 |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |