Skip to content

Commit

Permalink
feat: add git scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
nisavid committed Apr 12, 2024
1 parent fd36b56 commit e4b231a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
15 changes: 15 additions & 0 deletions home/private_dot_local/bin/executable_git-clean-disposable
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

root="$(git rev-parse --show-toplevel)"

ret=0
cd "$root" && {
for pathspec in db/schema.rb Gemfile*.lock; do
if [ -e "$pathspec" ]; then
git checkout HEAD -- "$pathspec" || { ret=$?; break; }
fi
done
# shellcheck disable=SC2164
cd - >/dev/null
}
exit $ret
19 changes: 19 additions & 0 deletions home/private_dot_local/bin/executable_git-config-branch-all-rebase
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

usage="$(basename "$0") [true|false]"

value='true'

case $# in
0) ;;
1) value='false' ;;
*) echo "$usage" >&2; exit 2 ;;
esac

for branch in $(git branch --list | cut -c 3-); do
if git branch --remotes | cut -c 3- | grep -q "^origin/$branch$" \
&& [ "$(git config branch."$branch".rebase)" != 'true' ]; then
echo setting branch "$branch" to rebase
git config branch."$branch".rebase "$value"
fi
done
10 changes: 10 additions & 0 deletions home/private_dot_local/bin/executable_git-grep-blame
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

grep_output="$(git grep "$@")" || exit

printf %s "$grep_output" \
| cut -d' ' -f1 \
| tr : ' ' \
| while read file line; do
git blame "$file" -L "$line",+1 --show-name
done
12 changes: 12 additions & 0 deletions home/private_dot_local/bin/executable_git-push-current-branch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

current_branch="$(git symbolic-ref --short HEAD)"

[ -z "$current_branch" ] && exit 1

# FIXME: ensure only one branch

remote=origin
[ $# -ge 1 ] && remote="$1"

git push -u "$remote" "$current_branch"
12 changes: 12 additions & 0 deletions home/private_dot_local/bin/executable_git-push-current-tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

current_tag="$(git tag --points-at HEAD)"

[ -z "$current_tag" ] && exit 1

# FIXME: ensure only one tag

remote=origin
[ $# -ge 1 ] && remote="$1"

git push --no-verify "$remote" "$current_tag"

0 comments on commit e4b231a

Please sign in to comment.