1
Fork 0

git: switch from aliases to standalone scripts

This commit is contained in:
Alan Faubert 2020-01-29 16:58:59 -05:00
parent 1dc70cd27b
commit 44dae94432
19 changed files with 52 additions and 30 deletions

View File

@ -33,7 +33,7 @@ For each profile:
- [uBlock Origin](https://addons.mozilla.org/addon/ublock-origin/)
- [YouTube Classic](https://addons.mozilla.org/addon/youtube-classic/)
## Git aliases
## Git scripts
- `git clean-branches` - delete local branches which track deleted remote branches
- `git clean-config` - unset various local config values, so global config will be used

View File

@ -7,7 +7,7 @@ while :; do
bash- 'Bash' bash-2path ' Set up 2path.sh script' bash-completion ' Set up ~/.bash_completion.d/' bash-git ' Set up Git status in prompt string' \
ssh- 'SSH' ssh ' Create config symlinks' ssh-win ' Create config symlinks (Windows)' \
dev- 'Development' dev ' Create ~/dev symlink to ..' \
git- 'Git' git ' Create config symlinks' git-win ' Create config symlinks (Windows)' git-filter-repo ' Install git-filter-repo' \
git- 'Git' git ' Create config symlinks' git-win ' Create config symlinks (Windows)' git-filter-repo ' Install git-filter-repo' git-scripts ' Set up various scripts' \
vscode- 'VS Code' vscode-ext ' Install extensions' vscode-linux ' Create config symlinks (Linux) ' vscode-win ' Create config symlinks (Windows)' vscode-local-win ' Create local extension symlink (Windows)' \
wsltty- 'WSLtty' wsltty ' Create config symlinks (Windows)' \
nodejs- 'Node.js' nodejs-nvm ' Install nvm' nodejs-npmrc ' Create .npmrc symlink' nodejs-pkg ' Create ../{pkg} symlinks' nodejs-eslint ' Create ../.eslintrc.js symlink' nodejs-sh ' Set up various scripts' \
@ -61,6 +61,9 @@ while :; do
wget https://github.com/newren/git-filter-repo/raw/master/git-filter-repo -O ~/bin/git-filter-repo &&
chmod 755 ~/bin/git-filter-repo
;;
git-scripts)
"$ROOT"/bash/2path.sh "$ROOT"/git/git-*
;;
vscode-ext)
code --install-extension dbaeumer.vscode-eslint --install-extension eamodio.gitlens --install-extension esbenp.prettier-vscode --install-extension pkief.material-icon-theme --install-extension streetsidesoftware.code-spell-checker
;;

View File

@ -1,19 +1,3 @@
[alias]
clean-branches = !git fetch --all -p && git branch -vv | awk '/: gone]/{print $1}' | xargs -r git branch -D
clean-config = "!git config --unset-all core.filemode; git config --unset-all core.ignorecase;"
clean-dates = "!f() { git diff HEAD --quiet && git filter-repo --force --refs ${1:-HEAD} --commit-callback 'commit.committer_date = commit.author_date'; }; f"
clean-modes = !git -c core.filemode diff -R | grep -E '^(diff|(old|new) mode)' | git apply
clean-pr = !git branch --list 'pr/*' | xargs -r git branch -D
clean-user = "!f() { git diff HEAD --quiet && git filter-repo --force --refs ${1:-HEAD} --commit-callback 'commit.author_email = commit.committer_email = b\"'\"$(git config --get user.email)\"'\"; commit.author_name = commit.committer_name = b\"'\"$(git config --get user.name)\"'\"'; }; f"
cpr = "!f() { \"$(dirname \"$(realpath ~/.gitconfig)\")\"/cpr \"$@\"; }; f"
index-list-skip = !git ls-files -v | grep ^S | cut -c3-
index-skip = update-index --skip-worktree
index-unskip = update-index --no-skip-worktree
npm-add = "!f() { \"$(dirname \"$(realpath ~/.gitconfig)\")\"/npm-add \"$@\"; }; f"
track = "!f() { [ $1 ] || exit 1; BRANCH=$(git symbolic-ref --short HEAD); git config branch.$BRANCH.remote $1; git config branch.$BRANCH.merge refs/heads/${2:-$BRANCH}; }; f"
turbo-gc = -c gc.reflogexpire=0 -c gc.reflogexpireunreachable=0 -c gc.rerereresolved=0 -c gc.rerereunresolved=0 -c gc.pruneexpire=now gc
user-acf = !git config --replace-all user.email 'git@acf.ws' && git config --replace-all user.name 'Alan Faubert'
user-conv = !git config --replace-all user.email 'git@chor.date' && git config --replace-all user.name 'Conduitry'
[core]
autocrlf = false
filemode = false

View File

@ -1,9 +0,0 @@
#!/bin/bash
set -e
[ $# = 1 ]
[[ "$(git remote get-url origin)" =~ [/@]github\.com[/:]([^/:]+)\/([^/]+)$ ]]
read REMOTE BRANCH < <(curl -s -H "Authorization: bearer $(cat "$(dirname "$0")"/../secrets/git/github_token)" -X POST -d "{\"query\":\"{ repository(owner: \\\"${BASH_REMATCH[1]}\\\", name: \\\"${BASH_REMATCH[2]%.git}\\\") { pullRequest(number: $1) { headRef { name } headRepository { nameWithOwner } } } }\"}" https://api.github.com/graphql | jq -r '.data.repository.pullRequest | "https://github.com/\(.headRepository.nameWithOwner) \(.headRef.name)"')
git fetch $REMOTE $BRANCH:pr/$1
git config branch.pr/$1.remote $REMOTE
git config branch.pr/$1.merge refs/heads/$BRANCH
git checkout pr/$1

2
git/git-clean-branches Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
git fetch --all -p && git branch -vv | awk '/: gone]/{print $1}' | xargs -r git branch -D

3
git/git-clean-config Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
git config --unset-all core.filemode
git config --unset-all core.ignorecase

4
git/git-clean-dates Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
set -e
git diff HEAD --quiet
git filter-repo --force --refs ${1:-HEAD} --commit-callback 'commit.committer_date = commit.author_date'

2
git/git-clean-modes Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
git -c core.filemode diff -R | grep -E '^(diff|(old|new) mode)' | git apply

2
git/git-clean-pr Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
git branch --list 'pr/*' | xargs -r git branch -D

4
git/git-clean-user Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
set -e
git diff HEAD --quiet
git filter-repo --force --refs ${1:-HEAD} --commit-callback 'commit.author_email = commit.committer_email = b"'"$(git config --get user.email)"'"; commit.author_name = commit.committer_name = b"'"$(git config --get user.name)"'"'

9
git/git-cpr Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
set -e
[ $# = 1 ]
[[ "$(git remote get-url origin)" =~ [/@]github\.com[/:]([^/:]+)\/([^/]+)$ ]]
read remote branch < <(curl -s -H "Authorization: bearer $(cat "$(dirname "$(readlink -e "$0")")"/../secrets/git/github_token)" -X POST -d "{\"query\":\"{ repository(owner: \\\"${BASH_REMATCH[1]}\\\", name: \\\"${BASH_REMATCH[2]%.git}\\\") { pullRequest(number: $1) { headRef { name } headRepository { nameWithOwner } } } }\"}" https://api.github.com/graphql | jq -r '.data.repository.pullRequest | "https://github.com/\(.headRepository.nameWithOwner) \(.headRef.name)"')
git fetch $remote $branch:pr/$1
git config branch.pr/$1.remote $remote
git config branch.pr/$1.merge refs/heads/$branch
git checkout pr/$1

2
git/git-index-list-skip Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
git ls-files -v | grep ^S | cut -c 3-

2
git/git-index-skip Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
git update-index --skip-worktree

2
git/git-index-unskip Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
git update-index --no-skip-worktree

View File

@ -1,4 +1,5 @@
#!/bin/sh
set -e
cd "$(git rev-parse --show-toplevel)"
cp package.json package.json.bak
node -e '
@ -11,7 +12,7 @@ node -e '
fs.writeFileSync("package.json", JSON.stringify(pkg, null, indent) + (str.endsWith("\n") ? "\n" : ""));
'
git rm --cached -rf .
PKG_TAR="$(npm pack | tail -n 1)"
tar tf "$PKG_TAR" | cut -c 9- | xargs -d '\n' git add -f
rm "$PKG_TAR"
pkg_tar="$(npm pack | tail -n 1)"
tar tf "$pkg_tar" | cut -c 9- | xargs -d '\n' git add -f
rm "$pkg_tar"
mv -f package.json.bak package.json

5
git/git-track Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
[ $1 ] || exit 1
branch=$(git symbolic-ref --short HEAD)
git config branch.$branch.remote $1
git config branch.$branch.merge refs/heads/${2:-$branch}

2
git/git-turbo-gc Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
git -c gc.reflogexpire=0 -c gc.reflogexpireunreachable=0 -c gc.rerereresolved=0 -c gc.rerereunresolved=0 -c gc.pruneexpire=now gc

2
git/git-user-acf Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
git config --replace-all user.email 'git@acf.ws' && git config --replace-all user.name 'Alan Faubert'

2
git/git-user-conv Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
git config --replace-all user.email 'git@chor.date' && git config --replace-all user.name 'Conduitry'