change: migrate default branch

Close #877.
This commit is contained in:
spacewander 2020-09-23 16:19:41 +08:00
parent e9668cc04b
commit 964663f1a4
12 changed files with 53 additions and 25 deletions

View file

@ -8,20 +8,20 @@ BRANCH=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
ARCHIVE_NAME=$(basename $(pwd))
if [[ $BRANCH = tags* ]]; then
BRANCH=$(git describe)
echo Building for tag \"$BRANCH\"
FILENAME=$ARCHIVE_NAME.$BRANCH.zip
BRANCH=$(git describe)
echo Building for tag \"$BRANCH\"
FILENAME=$ARCHIVE_NAME.$BRANCH.zip
else
echo Building archive on branch \"$BRANCH\"
# get a version string, so archives will not be overwritten when creating
# many of them
VERSION=$(git describe --always --long)
# if not on master append branch name into the filename
if [ "$BRANCH" = "master" ]; then
FILENAME=$ARCHIVE_NAME.$VERSION.zip
else
FILENAME=$ARCHIVE_NAME.$VERSION.$BRANCH.zip
fi
echo Building archive on branch \"$BRANCH\"
# get a version string, so archives will not be overwritten when creating
# many of them
VERSION=$(git describe --always --long)
# if not on master append branch name into the filename
if [ "$BRANCH" = $(git_extra_default_branch) ]; then
FILENAME=$ARCHIVE_NAME.$VERSION.zip
else
FILENAME=$ARCHIVE_NAME.$VERSION.$BRANCH.zip
fi
fi
# rename invalid chars for the file path

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
branches=$(git branch --no-color --merged | grep -v "\*" | grep -v master | grep -v svn)
branches=$(git branch --no-color --merged | grep -v "\*" | grep -v $(git_extra_default_branch) | grep -v svn)
if [ -n "$branches" ]
then
echo "$branches" | xargs -n 1 git branch -d

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
branch=master
branch=$(git_extra_default_branch)
filter=ACM
if test $# -eq 1; then

View file

@ -22,7 +22,7 @@ repository from scratch.
changed files will be reset, local branches and other remotes will be removed.
OPTIONS:
-b, --branch The branch to pull from the remote (default: master)
-b, --branch The branch to pull from the remote
-h, --help Display this help message
"
}

View file

@ -64,7 +64,7 @@ echo " create pull-request for $project '$branch'"
echo
printf " title: " && read -r title
printf " body: " && read -r body
printf " base [master]: " && read -r base
printf " base [%s]: " "$(git_extra_default_branch)" && read -r base
printf " GitHub two-factor authentication code (leave blank if not set up): " && read -r mfa_code
echo

View file

@ -1,3 +1,3 @@
#!/usr/bin/env bash
git branch --no-color --merged | grep -v "\*" | grep -v master | tr -d ' '
git branch --no-color --merged | grep -v "\*" | grep -v $(git_extra_default_branch) | tr -d ' '

View file

@ -1,3 +1,3 @@
#!/usr/bin/env bash
git branch --no-color --no-merged | grep -v "\*" | grep -v master | tr -d ' '
git branch --no-color --no-merged | grep -v "\*" | grep -v $(git_extra_default_branch) | tr -d ' '

View file

@ -43,8 +43,8 @@ commit_if_msg_provided() {
fi
}
prompt_continuation_if_squashing_master() {
if [[ $src =~ ^master$ ]]; then
prompt_continuation_if_squashing_default_branch() {
if [[ $src == $(git_extra_default_branch) ]]; then
read -p "Warning: squashing '$src'! Continue [y/N]? " -r
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Exiting"
@ -54,7 +54,7 @@ prompt_continuation_if_squashing_master() {
}
squash_branch() {
prompt_continuation_if_squashing_master
prompt_continuation_if_squashing_default_branch
if [ -n "$SQUASH_MSG" ]; then
base=$(git merge-base "$src" @)
msg=$(git log "$base".."$src" --format="%s%n%n%b" --no-merges --reverse)

View file

@ -5,3 +5,12 @@ git_extra_mktemp() {
mktemp -t "$(basename "$0")".XXXXXXX
}
git_extra_default_branch() {
local default_branch
default_branch=$(git config --get git-extras.default-branch)
if [ -z "$default_branch" ]; then
echo "master"
else
echo "$default_branch"
fi
}

View file

@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-EXTRAS" "1" "August 2020" "" "Git Extras"
.TH "GIT\-EXTRAS" "1" "September 2020" "" "Git Extras"
.
.SH "NAME"
\fBgit\-extras\fR \- Awesome GIT utilities
@ -27,6 +27,12 @@ update
.P
Self update\.
.
.SH "ENVIRONMENT AND CONFIGURATION VARIABLES"
\fBgit config \-\-add git\-extras\.default\-branch $BRANCH\fR
.
.P
Change the default branch to \fB$BRANCH\fR (defaut to \fBmaster\fR)\.
.
.SH "COMMANDS"
.
.IP "\(bu" 4

View file

@ -56,6 +56,7 @@
<a href="#NAME">NAME</a>
<a href="#SYNOPSIS">SYNOPSIS</a>
<a href="#OPTIONS">OPTIONS</a>
<a href="#ENVIRONMENT-AND-CONFIGURATION-VARIABLES">ENVIRONMENT AND CONFIGURATION VARIABLES</a>
<a href="#COMMANDS">COMMANDS</a>
<a href="#AUTHOR">AUTHOR</a>
<a href="#REPORTING-BUGS">REPORTING BUGS</a>
@ -91,6 +92,12 @@
<p> Self update.</p>
<h2 id="ENVIRONMENT-AND-CONFIGURATION-VARIABLES">ENVIRONMENT AND CONFIGURATION VARIABLES</h2>
<p> <code>git config --add git-extras.default-branch $BRANCH</code></p>
<p> Change the default branch to <code>$BRANCH</code> (defaut to <code>master</code>).</p>
<h2 id="COMMANDS">COMMANDS</h2>
<ul>
@ -165,7 +172,7 @@
<h2 id="AUTHOR">AUTHOR</h2>
<p>Written by Tj Holowaychuk &lt;<a href="&#109;&#x61;&#x69;&#108;&#x74;&#111;&#x3a;&#x74;&#106;&#x40;&#x76;&#105;&#115;&#105;&#111;&#110;&#45;&#x6d;&#101;&#100;&#105;&#97;&#x2e;&#99;&#x61;" data-bare-link="true">&#x74;&#x6a;&#64;&#118;&#x69;&#115;&#105;&#111;&#x6e;&#45;&#x6d;&#x65;&#x64;&#105;&#x61;&#46;&#99;&#97;</a>&gt;</p>
<p>Written by Tj Holowaychuk &lt;<a href="&#x6d;&#97;&#x69;&#x6c;&#116;&#x6f;&#58;&#116;&#106;&#64;&#118;&#x69;&#115;&#105;&#111;&#x6e;&#45;&#109;&#x65;&#x64;&#105;&#x61;&#x2e;&#99;&#97;" data-bare-link="true">&#116;&#x6a;&#64;&#118;&#105;&#115;&#x69;&#111;&#x6e;&#x2d;&#x6d;&#101;&#x64;&#x69;&#x61;&#x2e;&#x63;&#97;</a>&gt;</p>
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
@ -178,7 +185,7 @@
<ol class='man-decor man-foot man foot'>
<li class='tl'></li>
<li class='tc'>August 2020</li>
<li class='tc'>September 2020</li>
<li class='tr'>git-extras(1)</li>
</ol>

View file

@ -19,6 +19,12 @@ git-extras(1) -- Awesome GIT utilities
Self update.
## ENVIRONMENT AND CONFIGURATION VARIABLES
`git config --add git-extras.default-branch $BRANCH`
Change the default branch to `$BRANCH` (defaut to `master`).
## COMMANDS
- **git-alias(1)** Define, search and show aliases