-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
toolsets/repos: Add git-move-branch, git-get-branch-name & git-check-…
…branch-or-commit which are a more flexible and robust git-move-branch-to-head - which is thus removed ; Rename git-branch to git-new-branch ;
- Loading branch information
Showing
7 changed files
with
138 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
usage() { | ||
echo "usage: ${0##*/} branch|commit_id" | ||
echo "" | ||
echo " 'git-get-branch-name' then check that the branch name or commit exist in the current repo." | ||
echo "" | ||
exit 1 | ||
} | ||
if [ -z "$1" ]; then | ||
usage | ||
fi | ||
|
||
BRANCH_NAME=`git-get-branch-name "$1"` | ||
if [ `git rev-parse --verify "$BRANCH_NAME" 2>/dev/null` ] | ||
then | ||
echo "$BRANCH_NAME" | ||
exit 0 | ||
else | ||
echo "E/Can't find branch: '$BRANCH_NAME'" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/bash | ||
usage() { | ||
echo "usage: ${0##*/} (ORIGIN:)branch" | ||
echo "" | ||
echo " Get or detect the name of a branch." | ||
echo " " | ||
echo " Detectable branch name:" | ||
echo " main-branch|main_branch|master-branch|master_branch" | ||
echo " Name of the main branch, usually main or master." | ||
echo " current-branch|current_branch|." | ||
echo " Name of the current branch." | ||
echo "" | ||
echo " The 'ORIGIN:' prefix is useful to specifiy an origin and expand a detected" | ||
echo " branch name behind it. For example:" | ||
echo " $ ${0##*/} origin:main-branch" | ||
echo " > 'origin/main'" | ||
echo " $ ${0##*/} upstream:current-branch" | ||
echo " > 'upstream/my-current-work'" | ||
echo " " | ||
echo " Note: Use git-get-checked-branch-name to check if a branch name exists." | ||
exit 1 | ||
} | ||
|
||
if [ -z "$1" ]; then | ||
usage | ||
fi | ||
|
||
BRANCH=$1 | ||
if [[ $BRANCH == *":"* ]]; then | ||
ORIGIN=`echo "$BRANCH" | cut -d ":" -f 1` | ||
BRANCH=`echo "$BRANCH" | cut -d ":" -f 2` | ||
fi | ||
|
||
output_and_done() { | ||
if [ -n "$ORIGIN" ]; then | ||
echo $ORIGIN/$1 | ||
else | ||
echo $1 | ||
fi | ||
exit 0 | ||
} | ||
|
||
case "$BRANCH" in | ||
main-branch|main_branch|master-branch|master_branch) | ||
if [ `git rev-parse --verify main 2>/dev/null` ] | ||
then | ||
output_and_done main | ||
fi | ||
if [ `git rev-parse --verify master 2>/dev/null` ] | ||
then | ||
output_and_done master | ||
fi | ||
echo "cant_find_main_branch" | ||
;; | ||
current-branch|current_branch|.) | ||
CURRENT_BRANCH=`git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'` | ||
output_and_done "$CURRENT_BRANCH" | ||
;; | ||
*) | ||
output_and_done "$BRANCH" | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
usage() { | ||
echo "usage: ${0##*/} source (destination, default HEAD)" | ||
echo "" | ||
echo " Moves the source branch to point to the destination branch." | ||
echo "" | ||
exit 1 | ||
} | ||
|
||
case "$1" in | ||
-*) | ||
usage | ||
;; | ||
esac | ||
|
||
SRC=`git-check-branch-or-commit "$1"` | ||
if [ $? == 1 ]; then | ||
echo "E/Can't find source branch '$1'." | ||
usage | ||
fi | ||
|
||
DEST=`git-check-branch-or-commit "${2:-HEAD}"` | ||
if [ $? == 1 ]; then | ||
echo "E/Can't find destination branch/commit '$2'." | ||
usage | ||
fi | ||
|
||
SRC_COMMIT=`git rev-parse --verify --short=8 "$SRC"` | ||
DEST_COMMIT=`git rev-parse --verify --short=8 "$DEST"` | ||
|
||
echo "I/Moving '$SRC' ($SRC_COMMIT) to point to '$DEST' ($DEST_COMMIT)." | ||
(set -ex ; | ||
# Move the branch | ||
git branch -f $SRC $DEST | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters