summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-03-16 18:07:50 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-03-16 18:07:50 -0400
commitf4ae0c4fc9e630f40a12c7912c77aae3120658cc (patch)
tree9061faf051817376d76c6f7e0beade0d21a70963
parenta07981dc091b31127298c04a610f970cd5f1ad8d (diff)
Use git-sh-setup for git-rewrite-branch, clean up it's usage()
-rwxr-xr-xgit-rewrite-branch70
1 files changed, 56 insertions, 14 deletions
diff --git a/git-rewrite-branch b/git-rewrite-branch
index c9838cf..5135fdc 100755
--- a/git-rewrite-branch
+++ b/git-rewrite-branch
@@ -1,4 +1,31 @@
-#!/bin/bash -euE
+#!/bin/bash -eE
+#
+# Copyright (c) 2012-2013 Luke Shumaker <lukeshu@sbcglobal.net>
+#
+
+USAGE='[-h] [-v] [--svn] <in-branch> <out-branch> <filters>...'
+LONG_USAGE='Like filter-branch, but can be used to update branches.
+
+This creates or updates <out-branch> from <in-branch>. If <in-branch> already
+exists, it only runs new commits through the filter. This way, this can be
+used to pull from a remote with a different layout than yours.
+
+This will append "git-rewrite-id" to all commit messages, similar to
+"git-svn-id" with `git-svn`.
+
+ -h Show this text
+ -v Be more verbose
+ --svn Use an existing "git-svn-id" instead of "git-rewrite-id"
+ (in-branch was generated by git-svn)
+
+<filters> is passed directly to `git filter-branch`, and therefore has the same
+format.
+'
+SUBDIRECTORY_OP=Yes
+OPTIONS_SPEC=
+. git-sh-setup
+. git-sh-i18n
+require_work_tree_exists
# when $gitmode is true, $ibranch's commits are used as IDs
gitmode=true
@@ -8,19 +35,19 @@ ibranch=''
obranch=''
wbranch=''
-usage() {
- echo 'malformed call to internal function'
+panic() {
+ echo 'panic: malformed call to internal function'
+ exit 1
}
verbose() {
- : "$*"
- #echo "$*"
+ :
}
################################################################################
id2commit() {
- [[ $# = 2 ]] || { usage; return 1; }
+ [[ $# = 2 ]] || panic
local branch=$1
local id=$2
if [[ $branch == $ibranch ]] && $gitmode; then
@@ -31,7 +58,7 @@ id2commit() {
}
commit2id() {
- [[ $# = 2 ]] || { usage; return 1; }
+ [[ $# = 2 ]] || panic
local branch=$1
local commit=$2
if [[ $branch == $ibranch ]] && $gitmode; then
@@ -43,7 +70,7 @@ commit2id() {
# commit2commit
c2c() {
- [[ $# = 3 ]] || { usage; return 1; }
+ [[ $# = 3 ]] || panic
local from=$1
local to=$2
local commit=$3
@@ -60,15 +87,30 @@ c2c() {
main() {
# Parse command line arguments #########################################
- if [[ $1 = '--svn' ]]; then
- gitmode=false
- tag='git-svn-id'
- shift
- fi
+ while true; do
+ case "${1:-}" in
+ --svn)
+ gitmode=false
+ tag='git-svn-id'
+ shift
+ ;;
+ -h)
+ usage
+ return 0
+ ;;
+ -v)
+ verbose() { echo "$*"; }
+ shift
+ ;;
+ *)
+ break
+ ;;
+ esac
+ done
if [[ $# < 3 ]]; then
usage
- exit 1
+ return 1
fi
ibranch=$1