config/git: refactor a few repo commands into scripts
This commit is contained in:
parent
78da9ce041
commit
4a458a3c00
|
@ -97,7 +97,7 @@
|
||||||
lgo = lg HEAD @{push}
|
lgo = lg HEAD @{push}
|
||||||
lo = log --pretty=tformat:'%C(auto)%h%d %s %Cgreen(%cd) %Cblue<%an>%Creset' --date=human --no-merges
|
lo = log --pretty=tformat:'%C(auto)%h%d %s %Cgreen(%cd) %Cblue<%an>%Creset' --date=human --no-merges
|
||||||
lp = log -p --date=local
|
lp = log -p --date=local
|
||||||
ln = !git --no-pager lo "-$(a=$(git rev-list --count HEAD...@{push} 2>/dev/null); expr $a + 3 \\& ${a:-0} \\> 4 \\| 7)" --color=always --graph HEAD @{u} 2>/dev/null | head -9 || git --no-pager lo -7
|
ln = !git --no-pager lo "-$(a=$(git rev-list --count HEAD...@{push} 2>/dev/null); expr $a + 3 \\& ${a:-0} \\> 3 \\| 6)" --color=always --graph HEAD @{u} 2>/dev/null | head -9 || git --no-pager lo -7
|
||||||
my = lo --author [Jj]anek
|
my = lo --author [Jj]anek
|
||||||
standup = my --since yesterday --all
|
standup = my --since yesterday --all
|
||||||
co-authors = !git log | grep -i Co-Authored | awk '!a[$0]++'
|
co-authors = !git log | grep -i Co-Authored | awk '!a[$0]++'
|
||||||
|
@ -133,6 +133,7 @@
|
||||||
rs = reset --keep
|
rs = reset --keep
|
||||||
ru = reset --keep @{upstream}
|
ru = reset --keep @{upstream}
|
||||||
unstage = restore --staged --
|
unstage = restore --staged --
|
||||||
|
recover = restore --worktree --staged --
|
||||||
|
|
||||||
format-head = !git stash && git-clang-format HEAD~ && git commit -a --amend --no-edit && git stash pop
|
format-head = !git stash && git-clang-format HEAD~ && git commit -a --amend --no-edit && git stash pop
|
||||||
|
|
||||||
|
@ -151,7 +152,7 @@
|
||||||
ruu = !git fetch upstream && git reset --keep upstream/${1:-$(git curbranch)} && git push --no-verify --force-with-lease
|
ruu = !git fetch upstream && git reset --keep upstream/${1:-$(git curbranch)} && git push --no-verify --force-with-lease
|
||||||
luu = !git pull upstream ${1:-(git curbranch)} && git push --no-verify
|
luu = !git pull upstream ${1:-(git curbranch)} && git push --no-verify
|
||||||
pf = push --force-with-lease
|
pf = push --force-with-lease
|
||||||
cap = !git commit --all --amend --no-edit && git push --force-with-lease
|
cap = !git commit --amend --no-edit && git push --force-with-lease
|
||||||
|
|
||||||
[includeIf "gitdir:yadm/repo.git"]
|
[includeIf "gitdir:yadm/repo.git"]
|
||||||
path = "~/.config/yadm/gitconfig"
|
path = "~/.config/yadm/gitconfig"
|
||||||
|
|
|
@ -72,13 +72,6 @@ gitinit() {
|
||||||
git push
|
git push
|
||||||
}
|
}
|
||||||
|
|
||||||
gitbackup() {
|
|
||||||
p=$(basename $PWD)
|
|
||||||
builtin cd ..
|
|
||||||
git clone --mirror $p
|
|
||||||
cd $p
|
|
||||||
}
|
|
||||||
|
|
||||||
project() {
|
project() {
|
||||||
cd $projects_dir
|
cd $projects_dir
|
||||||
if [ -d $2 ]
|
if [ -d $2 ]
|
||||||
|
@ -87,23 +80,6 @@ project() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
gitremote() {
|
|
||||||
case "$1" in
|
|
||||||
http*) echo "git@$(echo "$1" | cut -d'/' -f3):$(echo "$1" | cut -d'/' -f4)/$(echo "$1" | cut -d'/' -f5)" ;;
|
|
||||||
git:*) echo "$1" ;;
|
|
||||||
*) test "$3" = "cau" && 3="CAU-Kiel-Tech-Inf"
|
|
||||||
test "$3" = "btl" && 3="betweenthelinesev"
|
|
||||||
echo "git@${1:-github.com}:${3:-$(git config user.name)}/${2:-$(basename $PWD)}.git" ;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
gitclone() {
|
|
||||||
remote=$(gitremote "$@")
|
|
||||||
echo $remote
|
|
||||||
git clone $remote ${@:4} || return $?
|
|
||||||
cd "$(test $4 && echo $4 || basename ${remote%.git})"
|
|
||||||
}
|
|
||||||
|
|
||||||
gitfork() {
|
gitfork() {
|
||||||
builtin cd "$projects_dir/_forks"
|
builtin cd "$projects_dir/_forks"
|
||||||
gitclone github.com "$1" "" "$3" --recurse-submodules || return $?
|
gitclone github.com "$1" "" "$3" --recurse-submodules || return $?
|
||||||
|
@ -111,30 +87,6 @@ gitfork() {
|
||||||
git remote -v
|
git remote -v
|
||||||
}
|
}
|
||||||
|
|
||||||
# set repo as origin and set all branches upstream to their respective remote branch, if available
|
|
||||||
gitorigin() {
|
|
||||||
git remote remove origin 2>/dev/null
|
|
||||||
git remote add origin $(gitremote "$@")
|
|
||||||
git remote -v && git fetch || ( last=$? && echo "git fetch failed, aborting\!" && return $last )
|
|
||||||
|
|
||||||
git branch | sed 's/ //g' | sed 's/*//' | while read branch
|
|
||||||
do test $(git branch -a | grep origin/$branch | wc -l) -gt 0 && git branch -u origin/$branch $branch
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
# set repo as upstream or add a new remote
|
|
||||||
gitupstream() {
|
|
||||||
if test "$3"
|
|
||||||
then
|
|
||||||
local name="$3"
|
|
||||||
git remote remove "$3" 2>/dev/null
|
|
||||||
else
|
|
||||||
git remote get-url upstream 2>/dev/null && local name="$1" || local name="upstream"
|
|
||||||
fi
|
|
||||||
local origin="$(git remote get-url origin)"
|
|
||||||
git remote add -f $name "$(echo $origin | cut -d':' -f1):$1/${2:-$(echo $origin | cut -d'/' -f2)}"
|
|
||||||
git remote -v
|
|
||||||
}
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# Rewriting history {{{
|
# Rewriting history {{{
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Creates a bare clone parallel to the current repository
|
||||||
|
p="$(basename "$(git rev-parse --show-toplevel)")"
|
||||||
|
builtin cd ..
|
||||||
|
git clone --mirror $p
|
||||||
|
builtin cd $p
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Clones from resolving the arguments and switches into the new directory
|
||||||
|
remote=$(gitremote "$@")
|
||||||
|
echo $remote
|
||||||
|
git clone $remote ${@:4} || return $?
|
||||||
|
cd "$(test $4 && echo $4 || basename ${remote%.git})"
|
|
@ -0,0 +1,9 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# set repo as origin and set all branches upstream to a corresponding remote branch, if available
|
||||||
|
git remote remove origin 2>/dev/null
|
||||||
|
git remote add origin $(git-repo "$@")
|
||||||
|
git remote -v && git fetch || ( last=$? && echo "git fetch failed, aborting\!" && return $last )
|
||||||
|
|
||||||
|
git branch | sed 's/ //g' | sed 's/*//' | while read branch
|
||||||
|
do test $(git branch -a | grep origin/$branch | wc -l) -gt 0 && git branch -u origin/$branch $branch
|
||||||
|
done
|
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Translates different repo notations into ssh
|
||||||
|
case "$1" in
|
||||||
|
http*) echo "git@$(echo "$1" | cut -d'/' -f3):$(echo "$1" | cut -d'/' -f4)/$(echo "$1" | cut -d'/' -f5)" ;;
|
||||||
|
git:*) echo "$1" ;;
|
||||||
|
*) echo "git@${1:-github.com}:${3:-$(git config user.name)}/${2:-$(basename $PWD)}.git" ;;
|
||||||
|
esac
|
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# set given repository as upstream or add as a new remote
|
||||||
|
if test "$3"
|
||||||
|
then
|
||||||
|
local name="$3"
|
||||||
|
git remote remove "$3" 2>/dev/null
|
||||||
|
else
|
||||||
|
git remote get-url upstream 2>/dev/null && local name="$1" || local name="upstream"
|
||||||
|
fi
|
||||||
|
local origin="$(git remote get-url origin)"
|
||||||
|
git remote add -f $name "$(echo $origin | cut -d':' -f1):$1/${2:-$(echo $origin | cut -d'/' -f2)}"
|
||||||
|
git remote -v
|
Loading…
Reference in New Issue