Compare commits

..

10 Commits

Author SHA1 Message Date
Joe Fleming
4dd974484f feat: add git snapshots, update helpers to work with wortrees 2026-02-19 13:20:11 -07:00
Joe Fleming
ffd0ae92d3 Update gitconfig
change b alias so it sorts by update and shows more info, add ll alias as a simple `l` replacement
2023-01-23 10:46:27 -07:00
bc42a3f8ef feat: auto rebase on git bsync command 2020-11-17 11:12:27 -07:00
a9ec765b5d chore: apply shellcheck fixes 2020-11-17 11:12:06 -07:00
4bdd001fb1 fix: unify around the zim git shortcuts, treailing x for delete
BREAKING CHANGE this replaces existing commands
2020-11-17 11:07:59 -07:00
d02733bff1 feat: add git fixup alias and signature support 2020-11-17 11:07:09 -07:00
Joe Fleming
815f54be68 feat: cherry-pick alias, add autosquash 2019-06-20 11:27:51 -07:00
f452ff65ac feat: add docker and misc aliases 2018-05-31 17:21:09 -07:00
56f3fbac81 fix: remove top alias 2018-05-31 17:15:15 -07:00
5dcd2cf0d2 fix: remove brew stuff
mac only :(
2018-05-31 16:29:37 -07:00
4 changed files with 197 additions and 70 deletions

View File

@@ -65,10 +65,6 @@ function parse_git_branch {
return return
} }
if [ -f `brew --prefix`/etc/bash_completion ]; then
. `brew --prefix`/etc/bash_completion
fi
export TERM="xterm-color" export TERM="xterm-color"
alias ls="ls -G" alias ls="ls -G"
export PS1="$PURPLE\u@\h$WHITE:$BLUE\w$YELLOW\$(parse_git_branch)$WHITE\$ " export PS1="$PURPLE\u@\h$WHITE:$BLUE\w$YELLOW\$(parse_git_branch)$WHITE\$ "

View File

@@ -6,6 +6,8 @@
bi = bisect bi = bisect
ci = commit ci = commit
co = checkout co = checkout
fu = commit --fixup
cp = cherry-pick
di = diff di = diff
dc = diff --cached dc = diff --cached
amend = commit --amend amend = commit --amend
@@ -18,15 +20,17 @@
gnc = goodness --cached gnc = goodness --cached
fa = fetch --all fa = fetch --all
pom = push origin master pom = push origin master
b = branch b = "!git for-each-ref --sort=-committerdate refs/heads --format='%(authordate:short) %(color:yellow)%(refname:short) %(color:red)%(objectname:short) %(color:reset) (%(color:green)%(committerdate:relative)%(color:reset))'"
ll = log --pretty='%C(yellow)%h %C(cyan)%cd %Cblue%aN%C(auto)%d %Creset%s' --graph --date=relative --topo-order --decorate
ds = diff --stat=160,120 ds = diff --stat=160,120
dh1 = diff HEAD~1 dh1 = diff HEAD~1
head = !git l -1 head = !git l -1
h = !git head h = !git head
hp = "!source ~/.githelpers && show_git_head" hs = !git head --show-signature
r = !git l -30 r = !git l -30
ra = !git r --all ra = !git r --all
rs = !git log --oneline --show-signature
l = "!source ~/.githelpers && pretty_git_log" l = "!source ~/.githelpers && pretty_git_log"
la = !git l --all la = !git l --all
sync = "!source ~/.githelpers && sync_to_remote" sync = "!source ~/.githelpers && sync_to_remote"
@@ -34,12 +38,19 @@
bp = !git backport bp = !git backport
backport = "!source ~/.githelpers && backport_pr" backport = "!source ~/.githelpers && backport_pr"
track = "!source ~/.githelpers && track_remote" track = "!source ~/.githelpers && track_remote"
sign = "!git commit -S --amend --no-edit"
todo = grep --heading --break --ignore-case -e ' FIX: *' -e ' TODO: *' todo = grep --heading --break --ignore-case -e ' FIX: *' -e ' TODO: *'
pr = "!source ~/.githelpers && get_pr" pr = "!source ~/.githelpers && get_pr"
prd = "!source ~/.githelpers && del_pr" prx = "!source ~/.githelpers && del_pr"
brc = "!source ~/.githelpers && clean_branches" brx = "!source ~/.githelpers && clean_branches"
lbr = for-each-ref --sort='-committerdate:iso8601' --format=' %(committerdate:iso8601)%09%(refname)' refs/heads lbr = for-each-ref --sort='-committerdate:iso8601' --format=' %(committerdate:iso8601)%09%(refname)' refs/heads
snc = "!source ~/.githelpers && create_snap"
sna = "!source ~/.githelpers && apply_snap"
snl = "!source ~/.githelpers && list_snaps"
snS = "!source ~/.githelpers && show_snap"
snr = "!source ~/.githelpers && revert_snap"
snx = "!source ~/.githelpers && remove_snap"
[merge] [merge]
tool = vimdiff tool = vimdiff
ff = true ff = true
@@ -48,3 +59,5 @@
followTags = true followTags = true
[branch] [branch]
autosetuprebase = always autosetuprebase = always
[rebase]
autosquash = true

View File

@@ -18,18 +18,21 @@ RELATIVE_TIME="%Cgreen(%ar)%Creset"
AUTHOR="%C(bold blue)<%an>%Creset" AUTHOR="%C(bold blue)<%an>%Creset"
REFS="%C(red)%d%Creset" REFS="%C(red)%d%Creset"
SUBJECT="%s" SUBJECT="%s"
DEFAULT_REMOTE="upstream" DEFAULT_REMOTE="origin"
ROOT_BRANCH="master" ROOT_BRANCH="master"
MAIN_BRANCH="main"
DEVELOP_BRANCH="development"
FORMAT="$HASH}$RELATIVE_TIME}$AUTHOR}$REFS $SUBJECT" FORMAT="$HASH}$RELATIVE_TIME}$AUTHOR}$REFS $SUBJECT"
show_git_head() { RED="\033[0;31m"
pretty_git_log -1 GREEN="\033[0;32m"
git show -p --pretty="tformat:" YELLOW="\033[0;33m"
} CYAN="\033[0;36m"
CRESET="\033[0m"
pretty_git_log() { pretty_git_log() {
git log --graph --pretty="tformat:${FORMAT}" $* | git log --graph --pretty="tformat:${FORMAT}" "$@" |
# Replace (2 years ago) with (2 years) # Replace (2 years ago) with (2 years)
#sed -Ee 's/(^[^<]*) ago)/\1)/' | #sed -Ee 's/(^[^<]*) ago)/\1)/' |
sed -e 's/ ago//' | sed -e 's/ ago//' |
@@ -43,92 +46,207 @@ pretty_git_log() {
} }
sync_to_remote() { sync_to_remote() {
REMOTE=$1 REMOTE="${1:-${DEFAULT_REMOTE}}"
: ${REMOTE:=$DEFAULT_REMOTE} BRANCH=$(git rev-parse --abbrev-ref HEAD)
BRANCH=`git rev-parse --abbrev-ref HEAD`
echo "Synching with ${REMOTE}" echo "Synching with ${YELLOW}${REMOTE}/${BRANCH}${CRESET}"
git fetch ${REMOTE} && git rebase ${REMOTE}/${BRANCH}; git fetch "${REMOTE}" && git rebase "${REMOTE}/${BRANCH}";
} }
update_branch() { update_branch() {
BRANCH=$1 BRANCH="${1:-${MAIN_BRANCH}}"
: ${BRANCH:=$ROOT_BRANCH} REMOTE="${2:-${DEFAULT_REMOTE}}"
REMOTE=$2
: ${REMOTE:=$DEFAULT_REMOTE} echo "Fetching ${YELLOW}${REMOTE}/${BRANCH}${CRESET} and rebasing with autostash"
echo Updating ${BRANCH} from ${REMOTE}
# check stash stack before and after # 1. Update the local ref for the target branch (worktree-safe)
old_stash=$(git rev-parse -q --verify refs/stash) git fetch "$REMOTE" "$BRANCH"
git stash
new_stash=$(git rev-parse -q --verify refs/stash) # 2. Rebase with integrated stash management
# checkout branch and sync to remote, then come back # --autostash: hides dirty files, rebases, then pops them back
git checkout ${BRANCH} && git sync ${REMOTE} && git checkout - if git rebase --autostash "$REMOTE/$BRANCH"; then
# if the stash added to the stack, pop it back off echo "${GREEN}Successfully updated and reapplied changes${CRESET}"
[ "$old_stash" != "$new_stash" ] && git stash pop git status --short
else
echo "${RED}Rebase conflict detected!${CRESET}"
echo "1. Fix conflicts -> git rebase --continue"
echo "2. Or abort -> git rebase --abort"
echo " If aborting, don't forget your stashed changes in the stash list"
return 1
fi
} }
get_pr() { get_pr() {
PR=$1 PR=$1
REMOTE=$2 REMOTE="${2:-${DEFAULT_REMOTE}}"
: ${REMOTE:=$DEFAULT_REMOTE}
if [ -z "$PR" ]; then if [ -z "$PR" ]; then
echo "Please specify a PR to checkout" echo "${RED}Please specify a PR to checkout${CRESET}"
exit 1 exit 1
fi fi
echo Checking out PR ${PR} from ${REMOTE} echo Checking out PR "${CYAN}${PR}${CRESET}" from "${YELLOW}${REMOTE}${CRESET}"
git fetch ${REMOTE} pull/${PR}/head:pr/${PR} git fetch "${REMOTE}" "pull/${PR}/head:pr/${PR}"
git checkout pr/${PR}
# Optimized count using grep -c
WT_COUNT=$(git worktree list --porcelain | grep -c "^worktree")
if [ "$WT_COUNT" -gt 1 ]; then
WT_NAME="PR-$PR"
echo "Worktrees detected. ${CYAN}Creating ${WT_NAME}${CRESET}"
git worktree add "PR-$PR" "pr/${PR}"
return
fi
# Fallback to normal checkout if no worktrees or user opts out
git checkout "pr/$PR"
} }
del_pr() { del_pr() {
BRANCH=`git rev-parse --abbrev-ref HEAD` BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ ! ${BRANCH} =~ ^pr\/ ]]; then if [[ ! ${BRANCH} =~ ^pr\/ ]]; then
echo "Not a PR branch, aborting!" echo "${RED}Not a PR branch, aborting!${CRESET}"
exit 1 exit 1
fi fi
git checkout - && git branch -D ${BRANCH}
if [ "$(git worktree list --porcelain | grep -c "^worktree")" -gt 1 ]; then
WT_PATH=$(git rev-parse --show-toplevel)
# echo "Worktrees detected. ${CYAN}Removing ${WT_PATH}${CRESET}"
git worktree remove "$WT_PATH" --force && git branch -D "$BRANCH"
echo "PR branch ${CYAN}${BRANCH}${CRESET} deleted and worktree ${CYAN}$(basename "$WT_PATH")${CRESET} removed"
echo "** ${GREEN}'cd ..' to return to the main repo${CRESET} **"
return
fi
# Fallback to normal branch deletion if no worktrees or user opts out
git checkout - && git branch -D "${BRANCH}"
} }
clean_branches() { clean_branches() {
BRANCHES=`git branch | grep -v 'master\|develop\|\*'` BRANCHES=$(git branch | grep -v "${ROOT_BRANCH}\|${MAIN_BRANCH}\|${DEVELOP_BRANCH}\|\*")
for i in ${BRANCHES}; do for i in ${BRANCHES}; do
git branch -d $i git branch -d "$i"
done done
} }
backport_pr() { backport_pr() {
PR=$1 echo "THIS NEEDS WORK - DO NOT USE YET"
BRANCH=$2 return 1
[ -z "$BRANCH" ] && BRANCH=`git rev-parse --abbrev-ref HEAD`
REMOTE=$3
: ${REMOTE:=$DEFAULT_REMOTE}
THISBRANCH=`git rev-parse --abbrev-ref HEAD`
URL="https://patch-diff.githubusercontent.com/raw/elastic/kibana/pull/${PR}.patch"
if [ -z "$PR" ]; then # PR=$1
echo "Please specify a PR to backport" # BRANCH=$2
exit 1 # [ -z "$BRANCH" ] && BRANCH=$(git rev-parse --abbrev-ref HEAD)
fi # REMOTE="${3:-${DEFAULT_REMOTE}}"
echo Backporting ${PR} to ${BRANCH} from ${REMOTE} # THISBRANCH=$(git rev-parse --abbrev-ref HEAD)
git checkout ${BRANCH} && git pull ${REMOTE} ${BRANCH} && curl -L -s "$URL" | git am # URL="https://patch-diff.githubusercontent.com/raw/elastic/kibana/pull/${PR}.patch"
# if the backport couldn't be cleanly applied, tell the user and exit # if [ -z "$PR" ]; then
if [ $? -ne 0 ]; then # echo "Please specify a PR to backport"
echo "FAILED - Backport could not be cleanly applied!" # exit 1
echo "FAILED - Fix by hand or run 'git am --abort'" # fi
exit 2
fi
# switch back if we didn't start in the target branch # echo "Backporting ${CYAN}${PR}${CRESET} to ${YELLOW}${BRANCH}${CRESET} from ${YELLOW}${REMOTE}${CRESET}"
[ "$THISBRANCH" != "$BRANCH" ] && git checkout -
# # if the backport couldn't be cleanly applied, tell the user and exit
# if ! git checkout "${BRANCH}" && git pull "${REMOTE}" "${BRANCH}" && curl -L -s "$URL" | git am
# then
# echo "FAILED - Backport could not be cleanly applied!"
# echo "FAILED - Fix by hand or run 'git am --abort'"
# exit 2
# fi
# # switch back if we didn't start in the target branch
# [ "$THISBRANCH" != "$BRANCH" ] && git checkout -
} }
track_remote() { track_remote() {
REMOTE=$1 REMOTE="${1:-${DEFAULT_REMOTE}}"
: ${REMOTE:="origin"}
BRANCH=$2 BRANCH=$2
[ -z "$BRANCH" ] && BRANCH=`git rev-parse --abbrev-ref HEAD`
git branch --set-upstream-to=${REMOTE}/${BRANCH} ${BRANCH} [ -z "$BRANCH" ] && BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "Setting ${CYAN}${BRANCH}${CRESET} to track ${YELLOW}${REMOTE}/${BRANCH}${CRESET}"
git branch --set-upstream-to="${REMOTE}/${BRANCH}" "${BRANCH}"
}
SNAPSHOT_DIR="$HOME/.git-snapshots"
create_snap() {
NAME=$1
if [ -z "$NAME" ]; then
echo "${RED}Error: Please specify a name for the snap.${CRESET}"
return 1
fi
mkdir -p "$SNAPSHOT_DIR"
FILE="$SNAPSHOT_DIR/${NAME}.patch"
if [ -f "$FILE" ]; then
echo "${RED}Error: Snap '$NAME' already exists.${CRESET}"
return 1
fi
git diff --cached > "$FILE" && git reset
}
apply_snap() {
NAME=$1
FILE="$SNAPSHOT_DIR/${NAME}.patch"
if [ ! -f "$FILE" ]; then
echo "${RED}Error: Snap '$NAME' not found.${CRESET}"
return 1
fi
echo "Applying snap ${CYAN}${NAME}${CRESET}"
git apply "$FILE"
}
list_snaps() {
echo "Snapshots in ${CYAN}$SNAPSHOT_DIR${CRESET}"
find "$SNAPSHOT_DIR" -maxdepth 1 -mindepth 1 -print0 | while IFS= read -r -d '' file; do
# $file is now safe to use, even with spaces or newlines
echo " $(basename "$file" .patch)"
done
}
revert_snap() {
NAME=$1
FILE="$SNAPSHOT_DIR/${NAME}.patch"
if [ ! -f "$FILE" ]; then
echo "${RED}Error: Snap '$NAME' not found.${CRESET}"
return 1
fi
echo "Reverting snap ${CYAN}${NAME}${CRESET}"
git apply --reverse "$FILE"
}
remove_snap() {
NAME=$1
FILE="$SNAPSHOT_DIR/${NAME}.patch"
if [ ! -f "$FILE" ]; then
echo "${RED}Error: Snap '$NAME' not found.${CRESET}"
return 1
fi
echo "Remove snap ${CYAN}${NAME}${CRESET} ? (y/n)"
read -r a
if [[ "$a" == [yY]* ]]; then
rm "$FILE"
else
echo "-- Aborted"
fi
}
show_snap() {
NAME=$1
FILE="$SNAPSHOT_DIR/${NAME}.patch"
if [ ! -f "$FILE" ]; then
echo "${RED}Error: Snap '$NAME' not found.${CRESET}"
return 1
fi
cat "$FILE"
} }

View File

@@ -31,7 +31,7 @@ fi
mkdir -p "${HOME}/bin" "${HOME}/.bash_aliases.d" "${HOME}/.bash_completion.d" "${HOME}/.bash_functions.d" mkdir -p "${HOME}/bin" "${HOME}/.bash_aliases.d" "${HOME}/.bash_completion.d" "${HOME}/.bash_functions.d"
cd "${ROOT}/bash/bash_magic/bash_aliases.d"; cd "${ROOT}/bash/bash_magic/bash_aliases.d";
for i in color refresh git less brew dev sublime top; do cp "${i}.sh" "${HOME}/.bash_aliases.d"; done for i in color refresh git less dev sublime docker misc; do cp "${i}.sh" "${HOME}/.bash_aliases.d"; done
cd "${ROOT}/bash/bash_magic/bash_completion.d"; cd "${ROOT}/bash/bash_magic/bash_completion.d";
for i in etc; do cp "${i}.sh" "${HOME}/.bash_completion.d"; done for i in etc; do cp "${i}.sh" "${HOME}/.bash_completion.d"; done
cd "${ROOT}/bash/bash_magic/bash_functions.d"; cd "${ROOT}/bash/bash_magic/bash_functions.d";