Skip to content

Commit

Permalink
Improve Gerrit git aliases, adding support for % push options (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecrs authored Aug 15, 2024
1 parent fc59bbc commit c4decc7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion home/.chezmoitemplates/get-github-head-revision
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{- if hasKey $revisions $repo -}}
{{- get $revisions $repo -}}
{{- else -}}
{{- $result := output "git" "ls-remote" (printf "https://github.com/%s.git" $repo) "HEAD" | trimSuffix "HEAD\n" | trim -}}
{{- $result := output "env" "GIT_CONFIG_GLOBAL=" "git" "ls-remote" (printf "https://github.com/%s.git" $repo) "HEAD" | trimSuffix "HEAD\n" | trim -}}
{{- $_ := set $revisions $repo $result -}}
{{- $result -}}
{{- end -}}
37 changes: 30 additions & 7 deletions home/dot_gitconfig.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,33 @@ path = ~/.config/gitalias/gitalias.txt
caa = commit --amend --all
caane = commit --amend --all --no-edit
cob = checkout -b
apply-gitignore = "!f() { set -ex; git rm -r --cached . >/dev/null; git add .; }; f"
remote-for-branch = "!f() { set -ex; branch="${1:-"$(git current-branch)"}"; git rev-parse --abbrev-ref --symbolic-full-name "${branch}@{upstream}" | sed -n 's,^\\(\\S*\\)/'"${branch}"'$,\\1,p'; }; f"
rr = "!f() { set -ex; branch="${1:-"$(git current-branch)"}"; remote="$(git remote-for-branch "${branch}")"; git reset --hard "${remote}/${branch}"; }; f"
pfor = "!f() { set -ex; branch="${1:-"$(git current-branch)"}"; remote="$(git remote-for-branch "${branch}")"; git push "${remote}" "HEAD:refs/for/${branch}"; }; f"
psfor = "!f() { set -ex; git caane; git pfor "$@"; }; f"
pdraft = "!f() { set -ex; branch="${1:-"$(git current-branch)"}"; remote="$(git remote-for-branch "${branch}")"; git push "${remote}" "HEAD:refs/drafts/${branch}"; }; f"
psdraft = "!f() { set -ex; git caane; git pdraft "$@"; }; f"
apply-gitignore = "!f() { \
set -ex; \
git rm -r --cached . >/dev/null; \
git add .; \
};f"
remote-for-branch = "!f() { \
set -ex; \
branch="${1:-"$(git current-branch)"}"; \
git rev-parse --abbrev-ref --symbolic-full-name "${branch}@{upstream}" | sed -n 's,^\\(\\S*\\)/'"${branch}"'$,\\1,p' | grep .; \
};f"
rr = "!f() { \
set -ex; \
branch="${1:-"$(git current-branch)"}"; \
remote="$(git remote-for-branch "${branch}")"; \
git reset --hard "${remote}/${branch}"; \
};f"
pfor = "!f() { \
set -ex; \
branch="$(echo "${1}" | cut -d'%' -f1)"; \
branch="${branch:-"$(git current-branch)"}"; \
push_opts="$(echo "${1}" | cut -d'%' -f2-)"; \
push_opts="${push_opts:+"%${push_opts}"}"; \
remote="$(git remote-for-branch "${branch}")"; \
git push "${remote}" "HEAD:refs/for/${branch}${push_opts}"; \
};f"
psfor = "!f() { \
set -ex; \
git caane; \
git pfor "$@"; \
};f"

0 comments on commit c4decc7

Please sign in to comment.