Permalink
Browse files

Maintenance: whitespace, comments, general cleanup

  • Loading branch information...
1 parent 467c95a commit 5845bf2e1c1919acd5f068723a6f7ce33b6863be @jamiew committed Aug 22, 2011
Showing with 20 additions and 19 deletions.
  1. +11 −11 branch
  2. +2 −5 merge
  3. +2 −0 pull
  4. +5 −3 push
View
22 branch
@@ -1,25 +1,26 @@
#!/bin/sh
-#
-# branch [branchname]
#
-# Create a new local AND remote git branch
-# Setup local branch to use remote tracking
+# Usage: branch [branchname]
+#
+#
+# Switch to an existing branch or creates a new local-only branch
+# Adds remote tracking if a remote branch with the same name exists
+# Executing without arguments prints all local & remote branches
#
+remote="origin"
branch=$1
+
if [ -z $branch ]; then
- echo "\nSwitch to or create a new branch:"
+ echo "\nSwitch to or create a new branch:"
echo " $0 [name]"
echo "\nCurrent branches: "
- branches="git branch -a -v"
+ branches="git branch -a -vv"
$branches
echo
exit 0
fi
-# You were probably on master, but just in case...
-old_branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
-remote=origin
local_branch_exists=$(git branch | egrep "$branch\$")
remote_branch_exists=$(git branch -r | egrep "$remote/$branch\$")
@@ -41,13 +42,12 @@ if [ -n "$local_branch_exists" ] && [ ! "$local_branch_exists" == '' ]; then
# echo "Remote branch does not exist, not doing anything"
fi
-# If remote exists, create local branch that tracks the remote
+# If remote exists, create a local branch that tracks the remote
elif [ -n "$remote_branch_exists" ] && [ ! "$remote_branch_exists" == '' ]; then
echo "* Tracking existing remote branch..."
git checkout -b $branch --track $remote/$branch
# Otherwise create a new local branch
-# We used to create a remote branche too, but you can just do that by using `push`
else
echo "* Creating new local branch..."
git checkout -b $branch
View
7 merge
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# merge [branchname]
+# Usage: merge [branchname]
#
# Tries to merge local branch "branchname" into the current branch
# It will stop you if you are behind & need to pull 1st
@@ -9,6 +9,7 @@
remote="origin"
branch=$1
current_branch=$(git branch 2>/dev/null|grep -e ^* | tr -d \*//)
+
if [ -z $branch ]; then
echo "Usage: $0 [branchname]"
exit 1
@@ -30,9 +31,5 @@ echo "* Merge $branch into $current_branch"
git checkout $current_branch
git merge $branch || exit 1
-# Idea: delete local and/or remote branch (?)
-# echo "* Deleting merged local branch..."
-# git branch -d $branch || exit 1
-
echo "* Done"
exit 0
View
2 pull
@@ -31,11 +31,13 @@ git remote prune $remote
# Bundle em if you got em!
if which -s bundle && [ -f Gemfile ]; then
+ echo "* Bundling gems..."
bundle check >/dev/null 2>&1 || bundle install
fi
# Install node.js/npm packages
if which -s npm && [ -f package.json ]; then
+ echo "* Installing npm packages..."
npm install
fi
View
8 push
@@ -10,12 +10,13 @@
# e.g. for doing "push -f"
#
-remote=origin
+remote="origin"
branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
# Push & save output
push=$(git push --set-upstream $* $remote $branch 2>&1)
exit_code=$?
+
if [ $exit_code != 0 ]; then
echo "Ouch, push failed! code=$exit_code, output=$push"
exit $exit_code
@@ -42,8 +43,9 @@ if [[ "$remote_url" =~ "github.com" ]]; then
github_url="https://github.com/$repo_name/compare/$refs"
which -s pbcopy && echo $github_url | pbcopy && echo "Compare URL copied to clipboard!"
# which -s open && open -g $github_url
- echo $github_url
+ echo $github_url
echo
fi
-exit 0
+
+exit 0

0 comments on commit 5845bf2

Please sign in to comment.