Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

incoming and outgoing improvements #19

Closed
wants to merge 19 commits into from

2 participants

@configurator

First, show an error message when the current branch can't be found (e.g. because we're not in a git repository) - applies to git-incoming and git-outgoing.

Also, add git-rstatus, which shows status incoming and outgoing (and does a fetch so that incoming is actually up to date).

configurator added some commits
@configurator configurator Show an error message when the current branch can't be found (e.g. be…
…cause we're not in a git repository).
83fadc2
@configurator configurator Add remote status operation (rstatus), which shows status, incoming a…
…nd outgoing.
0fb8f24
@configurator configurator Remove color-first-word, which isn't part of this repository and shou…
…ldn't have been committed in the first

place.
f406413
@configurator configurator Add a list of current stashes to git-rstatus. 12a29e5
@configurator configurator git-sync: When there are no local changes, pulls then pushes. 6617ccd
@configurator configurator Don't call git rm with empty lists dedf81e
@configurator configurator Consolide the branch selection for git-incoming and git-outgoing; use…
… it for git-rstatus as well.
166542f
@configurator configurator Add the option to stash when calling git sync. 60e9d91
@configurator configurator - Add the option to not fetch in git rstatus.
- Disable the pager in git rstatus, as it pages over each part intead of the entire thing.
b8aa8f1
@configurator configurator When calling git sync --stash, only pop the stash if we actually save…
…d something in it.
765b773
@configurator configurator Use fetch-rebase-push when syncing, instead of merge. Accept paramete…
…r to control repo & branch.
04549d8
@configurator configurator Simplify git-rstatus and git-sync with a bash include file. f30c794
@configurator configurator - Make sync --rebase an option.
- 2 bugfixes in git sync
e8fb4a0
@configurator configurator Add branch when pulling so syncing with non-origin sources still works. 2ab5fc8
@configurator configurator Make readlink work correctly, as well as starting git-incoming and gi…
…t-outgoing, when links are not setup.
66ef29c
@configurator configurator Use --no-pager for incoming and outgoing from within git-rstatus 7007b88
@configurator configurator Use true/false instead of 1/0 5f4bd5d
@configurator configurator Use branch name when pushing as well as pulling; imporve help message. f32c074
@configurator configurator Merge branch 'master' of gh:ddollar/git-utils
Conflicts:
	git-addremove
66615e7
@ddollar
Owner

Hello. I apologize for not responding earlier but I am currently declaring Github bankruptcy. If this pull request or issue is still valid please feel free to re-open and explain.

@ddollar ddollar closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 23, 2012
  1. @configurator

    Show an error message when the current branch can't be found (e.g. be…

    configurator authored
    …cause we're not in a git repository).
Commits on Aug 26, 2012
  1. @configurator
Commits on Aug 28, 2012
  1. @configurator

    Remove color-first-word, which isn't part of this repository and shou…

    configurator authored
    …ldn't have been committed in the first
    
    place.
  2. @configurator
  3. @configurator
Commits on Aug 30, 2012
  1. @configurator
  2. @configurator

    Consolide the branch selection for git-incoming and git-outgoing; use…

    configurator authored
    … it for git-rstatus as well.
Commits on Sep 4, 2012
  1. @configurator
  2. @configurator

    - Add the option to not fetch in git rstatus.

    configurator authored
    - Disable the pager in git rstatus, as it pages over each part intead of the entire thing.
  3. @configurator
Commits on Sep 11, 2012
  1. @configurator
  2. @configurator
Commits on Sep 15, 2012
  1. @configurator

    - Make sync --rebase an option.

    configurator authored
    - 2 bugfixes in git sync
Commits on Sep 27, 2012
  1. @configurator
Commits on Oct 11, 2012
  1. @configurator

    Make readlink work correctly, as well as starting git-incoming and gi…

    configurator authored
    …t-outgoing, when links are not setup.
Commits on Oct 14, 2012
  1. @configurator
Commits on Oct 23, 2012
  1. @configurator
  2. @configurator
Commits on Oct 14, 2014
  1. @configurator

    Merge branch 'master' of gh:ddollar/git-utils

    configurator authored
    Conflicts:
    	git-addremove
This page is out of date. Refresh to see the latest.
View
77 bash-functions
@@ -0,0 +1,77 @@
+#!/bin/bash
+
+colortitle() {
+ # Usage: colortitle ansi_color text
+ # Writes a title with the specified ANSI color, in bold, with a blank line before it
+
+ local color="$1"
+ shift
+
+ echo
+ echo -e "\033[$color;1m$*\033[0m"
+}
+red() { colortitle 31 "$@"; }
+green() { colortitle 32 "$@"; }
+blue() { colortitle 34 "$@"; }
+
+assert_git_repo() {
+ # Asserts the current folder is a git repository.
+
+ git branch >& /dev/null
+ if (( $? != 0 )); then
+ blue Not a git repo.
+ exit 401
+ fi
+}
+
+assert_clear_status() {
+ # Asserts there are no current changes, i.e. git status returns nothing.
+
+ local status="$(git status --porcelain 2> /dev/null)"
+ if (( $? != 0 )) || [[ "$status" != "" ]]; then
+ red "Stopping due to unclear status"
+ [[ $# != 0 ]] && echo "$*"
+ echo
+ git status
+ echo
+ exit 403
+ fi
+}
+
+parse_source_args() {
+ # Sets the globals $source and $branch according to the current branch or given parameters.
+
+ assert_git_repo
+
+ if (( $# > 1 )); then
+ echo Too many command-line parameters.
+ [[ "$(type -t usage)" == "function" ]] && usage
+ exit 402
+ fi
+
+ local current_branch="$(git branch | grep '^*' | sed 's#\* ##')"
+ if [[ "$current_branch" == "" ]]; then
+ echo Cannot determine current branch
+ exit 501
+ fi
+
+ case "$1" in
+ '')
+ source="$(git config branch.${current_branch}.remote)"
+ if [[ "$source" == "" ]]; then
+ echo Cannot determine tracking repository
+ exit 502
+ fi
+ local remote_branch="$(git config branch.${current_branch}.merge | sed -e 's#^[^/]*/[^/]*/##')"
+ branch="$source/$remote_branch"
+ ;;
+ */*)
+ branch="$1"
+ source="$(echo "$1" | sed -e 's#^remote##' -e 's#/.*##')"
+ ;;
+ *)
+ branch="$1/master"
+ source="$1"
+ ;;
+ esac
+}
View
2  git-addremove
@@ -3,4 +3,4 @@
FILES=${@:-:/}
git add -A $FILES
-git ls-files --deleted -z $FILES | xargs -0 git rm
+git ls-files --deleted -z $FILES | xargs -0 --no-run-if-empty git rm
View
33 git-incoming
@@ -1,24 +1,15 @@
#!/bin/bash
-CURRENT_BRANCH=$(git branch &>/dev/null; if [ $? -eq 0 ]; then echo "$(git branch | grep '^*' |sed s/\*\ //)"; fi)
+git_options=''
+while [[ "$1" == -* ]]; do
+ git_options="$git_options$1 "
+ shift
+done
-if [ "${CURRENT_BRANCH}" != "" ]; then
-
- TARGET="${1}"
-
- if [ "${TARGET}" == "" ]; then
- TRACKING_REPOSITORY="$(git config branch.${CURRENT_BRANCH}.remote)"
-
- # there is a tracking repository
- if [ "${TRACKING_REPOSITORY}" != "" ]; then
- REMOTE_REPOSITORY="${TRACKING_REPOSITORY}"
- REMOTE_BRANCH="$(git config branch.${CURRENT_BRANCH}.merge | sed -e 's#^[^/]*/[^/]*/##')"
- TARGET="${REMOTE_REPOSITORY}/${REMOTE_BRANCH}"
- fi
- fi
-
- echo "From: ${TARGET}"
- echo ""
-
- git log ..${TARGET}
-fi
+. "$(dirname "$(readlink -m "$0")")/bash-functions"
+parse_source_args "$@"
+
+echo "From: $branch"
+echo ""
+
+git $git_options log "..$branch" --oneline
View
33 git-outgoing
@@ -1,24 +1,15 @@
#!/bin/bash
-CURRENT_BRANCH=$(git branch &>/dev/null; if [ $? -eq 0 ]; then echo "$(git branch | grep '^*' |sed s/\*\ //)"; fi)
+git_options=''
+while [[ "$1" == -* ]]; do
+ git_options="$git_options$1 "
+ shift
+done
-if [ "${CURRENT_BRANCH}" != "" ]; then
-
- TARGET="${1}"
-
- if [ "${TARGET}" == "" ]; then
- TRACKING_REPOSITORY="$(git config branch.${CURRENT_BRANCH}.remote)"
-
- # there is a tracking repository
- if [ "${TRACKING_REPOSITORY}" != "" ]; then
- REMOTE_REPOSITORY="${TRACKING_REPOSITORY}"
- REMOTE_BRANCH="$(git config branch.${CURRENT_BRANCH}.merge | sed -e 's#^[^/]*/[^/]*/##')"
- TARGET="${REMOTE_REPOSITORY}/${REMOTE_BRANCH}"
- fi
- fi
-
- echo "To: ${TARGET}"
- echo ""
-
- git log ${TARGET}..
-fi
+. "$(dirname "$(readlink -m "$0")")/bash-functions"
+parse_source_args "$@"
+
+echo "To: $branch"
+echo ""
+
+git $git_options log "$branch.." --oneline
View
56 git-rstatus
@@ -0,0 +1,56 @@
+#!/bin/bash
+
+dir="$(dirname "$(readlink -m "$0")")"
+. "$dir/bash-functions"
+
+usage() {
+ blue "Usage:"
+ cat <<-USAGE
+ $0
+ $0 repo
+ $0 repo/branch
+ Example:
+ $0
+ $0 origin
+ $0 origin/master
+ USAGE
+ exit 1
+}
+
+fetch=1
+
+while [[ "$1" == -* ]]; do
+ case "$1" in
+ --no-fetch)
+ fetch=0
+ ;;
+ *)
+ usage
+ ;;
+ esac
+ shift
+done
+
+parse_source_args "$@"
+
+clear
+
+green Local status
+git --no-pager status
+(( "$?" != 0 )) && exit $?
+
+green Stashes
+git --no-pager stash list --oneline
+
+if (( "$fetch" == 1 )); then
+ green "Fetching $source..."
+ git --no-pager fetch "$source" -v
+fi
+
+green "Incoming changes:"
+"$dir/git-incoming" --no-pager "$branch"
+
+green "Outgoing changes:"
+"$dir/git-outgoing" --no-pager "$branch"
+
+echo
View
75 git-sync
@@ -0,0 +1,75 @@
+#!/bin/bash
+
+. "$(dirname "$(readlink -m "$0")")/bash-functions"
+
+usage() {
+ blue "Usage"
+ cat <<-USAGE
+ $0 [options] [repo[/branch]]
+ Fetch, rebase, and push.
+
+ repo/branch
+ Specifies where to fetch from, pull to, and what to merge with.
+
+ options
+ --stash
+ Saves the current status in stash before syncing, and pops afterwards.
+
+ --rebase
+ Uses pull --rebase instead of merge
+
+ USAGE
+ exit 1
+}
+
+stash=false
+rebase=''
+while [[ "$1" == -* ]]; do
+ case "$1" in
+ --stash)
+ stash=true
+ ;;
+ --rebase)
+ rebase='--rebase'
+ ;;
+ *)
+ usage
+ ;;
+ esac
+ shift
+done
+
+parse_source_args "$@"
+
+
+if $stash; then
+ old_stash_count=$(git stash list | wc -l)
+
+ green Stashing
+ git stash save
+
+ new_stash_count=$(git stash list | wc -l)
+ if (( $new_stash_count == $old_stash_count )); then
+ # The stash save didn't do anything; turn off stashing so we don't pop anything either.
+ stash=0
+ fi
+else
+ assert_clear_status "To stash before and after syncing, call git sync --stash"
+fi
+
+branch="${branch/*\//}"
+
+green Pulling $source $rebase
+git pull $rebase "$source" "$branch" || exit 1
+assert_clear_status
+
+green Pushing
+git push "$source" HEAD:"$branch"
+assert_clear_status
+
+if $stash; then
+ green Popping the stash
+ git stash pop
+fi
+
+echo
Something went wrong with that request. Please try again.