Skip to content

Commit

Permalink
Use git_do where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromebaum committed Sep 25, 2012
1 parent 5bca8d9 commit 15aab26
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 92 deletions.
58 changes: 29 additions & 29 deletions git-flow-feature
Expand Up @@ -204,7 +204,7 @@ cmd_start() {

# update the local repo with remote changes, if asked
if flag fetch; then
git fetch -q "$ORIGIN" "$DEVELOP_BRANCH"
git_do fetch -q "$ORIGIN" "$DEVELOP_BRANCH"
fi

# if the origin branch counterpart exists, assert that the local branch
Expand All @@ -214,7 +214,7 @@ cmd_start() {
fi

# create branch
if ! git checkout -b "$BRANCH" "$BASE"; then
if ! git_do checkout -b "$BRANCH" "$BASE"; then
die "Could not create feature branch '$BRANCH'"
fi

Expand Down Expand Up @@ -287,8 +287,8 @@ cmd_finish() {
# update local repo with remote changes first, if asked
if has "$ORIGIN/$BRANCH" $(git_remote_branches); then
if flag fetch; then
git fetch -q "$ORIGIN" "$BRANCH"
git fetch -q "$ORIGIN" "$DEVELOP_BRANCH"
git_do fetch -q "$ORIGIN" "$BRANCH"
git_do fetch -q "$ORIGIN" "$DEVELOP_BRANCH"
fi
fi

Expand All @@ -311,16 +311,16 @@ cmd_finish() {
fi

# merge into BASE
git checkout "$DEVELOP_BRANCH"
git_do checkout "$DEVELOP_BRANCH"
if [ "$(git rev-list -n2 "$DEVELOP_BRANCH..$BRANCH" | wc -l)" -eq 1 ]; then
git merge --ff "$BRANCH"
git_do merge --ff "$BRANCH"
else
if noflag squash; then
git merge --no-ff "$BRANCH"
git_do merge --no-ff "$BRANCH"
else
git merge --squash "$BRANCH"
git commit
git merge "$BRANCH"
git_do merge --squash "$BRANCH"
git_do commit
git_do merge "$BRANCH"
fi
fi

Expand Down Expand Up @@ -351,15 +351,15 @@ helper_finish_cleanup() {

# delete branch
if flag fetch; then
git push "$ORIGIN" ":refs/heads/$BRANCH"
git_do push "$ORIGIN" ":refs/heads/$BRANCH"
fi


if noflag keep; then
if flag force_delete; then
git branch -D "$BRANCH"
git_do branch -D "$BRANCH"
else
git branch -d "$BRANCH"
git_do branch -d "$BRANCH"
fi
fi

Expand All @@ -383,17 +383,17 @@ cmd_publish() {
# sanity checks
require_clean_working_tree
require_branch "$BRANCH"
git fetch -q "$ORIGIN"
git_do fetch -q "$ORIGIN"
require_branch_absent "$ORIGIN/$BRANCH"

# create remote branch
git push "$ORIGIN" "$BRANCH:refs/heads/$BRANCH"
git fetch -q "$ORIGIN"
git_do push "$ORIGIN" "$BRANCH:refs/heads/$BRANCH"
git_do fetch -q "$ORIGIN"

# configure remote tracking
git config "branch.$BRANCH.remote" "$ORIGIN"
git config "branch.$BRANCH.merge" "refs/heads/$BRANCH"
git checkout "$BRANCH"
git_do config "branch.$BRANCH.remote" "$ORIGIN"
git_do config "branch.$BRANCH.merge" "refs/heads/$BRANCH"
git_do checkout "$BRANCH"

echo
echo "Summary of actions:"
Expand All @@ -410,11 +410,11 @@ cmd_track() {
# sanity checks
require_clean_working_tree
require_branch_absent "$BRANCH"
git fetch -q "$ORIGIN"
git_do fetch -q "$ORIGIN"
require_branch "$ORIGIN/$BRANCH"

# create tracking branch
git checkout -b "$BRANCH" "$ORIGIN/$BRANCH"
git_do checkout -b "$BRANCH" "$ORIGIN/$BRANCH"

echo
echo "Summary of actions:"
Expand Down Expand Up @@ -445,7 +445,7 @@ cmd_checkout() {

if [ "$NAME" != "" ]; then
expand_nameprefix_arg
git checkout "$BRANCH"
git_do checkout "$BRANCH"
else
die "Name a feature branch explicitly."
fi
Expand All @@ -464,12 +464,12 @@ cmd_rebase() {
require_clean_working_tree
require_branch "$BRANCH"

git checkout -q "$BRANCH"
git_do checkout -q "$BRANCH"
local OPTS=
if flag interactive; then
OPTS="$OPTS -i"
fi
git rebase $OPTS "$DEVELOP_BRANCH"
git_do rebase $OPTS "$DEVELOP_BRANCH"
}

avoid_accidental_cross_branch_action() {
Expand Down Expand Up @@ -511,20 +511,20 @@ cmd_pull() {
# we already have a local branch called like this, so simply pull the
# remote changes in
if flag rebase; then
if ! git pull --rebase -q "$REMOTE" "$BRANCH"; then
if ! git_do pull --rebase -q "$REMOTE" "$BRANCH"; then
warn "Pull was aborted. There might be conflicts during rebase or '$REMOTE' might be inaccessible."
exit 1
fi
else
git pull -q "$REMOTE" "$BRANCH" || die "Failed to pull from remote '$REMOTE'."
git_do pull -q "$REMOTE" "$BRANCH" || die "Failed to pull from remote '$REMOTE'."
fi

echo "Pulled $REMOTE's changes into $BRANCH."
else
# setup the local branch clone for the first time
git fetch -q "$REMOTE" "$BRANCH" || die "Fetch failed." # stores in FETCH_HEAD
git branch --no-track "$BRANCH" FETCH_HEAD || die "Branch failed."
git checkout -q "$BRANCH" || die "Checking out new local branch failed."
git_do fetch -q "$REMOTE" "$BRANCH" || die "Fetch failed." # stores in FETCH_HEAD
git_do branch --no-track "$BRANCH" FETCH_HEAD || die "Branch failed."
git_do checkout -q "$BRANCH" || die "Checking out new local branch failed."
echo "Created local branch $BRANCH based on $REMOTE's $BRANCH."
fi
}
38 changes: 19 additions & 19 deletions git-flow-hotfix
Expand Up @@ -169,14 +169,14 @@ cmd_start() {
require_branch_absent "$BRANCH"
require_tag_absent "$VERSION_PREFIX$VERSION"
if flag fetch; then
git fetch -q "$ORIGIN" "$MASTER_BRANCH"
git_do fetch -q "$ORIGIN" "$MASTER_BRANCH"
fi
if has "$ORIGIN/$MASTER_BRANCH" $(git_remote_branches); then
require_branches_equal "$MASTER_BRANCH" "$ORIGIN/$MASTER_BRANCH"
fi

# create branch
git checkout -b "$BRANCH" "$BASE"
git_do checkout -b "$BRANCH" "$BASE"

echo
echo "Summary of actions:"
Expand All @@ -199,17 +199,17 @@ cmd_publish() {
# sanity checks
require_clean_working_tree
require_branch "$BRANCH"
git fetch -q "$ORIGIN"
git_do fetch -q "$ORIGIN"
require_branch_absent "$ORIGIN/$BRANCH"

# create remote branch
git push "$ORIGIN" "$BRANCH:refs/heads/$BRANCH"
git fetch -q "$ORIGIN"
git_do push "$ORIGIN" "$BRANCH:refs/heads/$BRANCH"
git_do fetch -q "$ORIGIN"

# configure remote tracking
git config "branch.$BRANCH.remote" "$ORIGIN"
git config "branch.$BRANCH.merge" "refs/heads/$BRANCH"
git checkout "$BRANCH"
git_do checkout "$BRANCH"

echo
echo "Summary of actions:"
Expand All @@ -226,11 +226,11 @@ cmd_track() {
# sanity checks
require_clean_working_tree
require_branch_absent "$BRANCH"
git fetch -q "$ORIGIN"
git_do fetch -q "$ORIGIN"
require_branch "$ORIGIN/$BRANCH"

# create tracking branch
git checkout -b "$BRANCH" "$ORIGIN/$BRANCH"
git_do checkout -b "$BRANCH" "$ORIGIN/$BRANCH"

echo
echo "Summary of actions:"
Expand Down Expand Up @@ -260,9 +260,9 @@ cmd_finish() {
require_branch "$BRANCH"
require_clean_working_tree
if flag fetch; then
git fetch -q "$ORIGIN" "$MASTER_BRANCH" || \
git_do fetch -q "$ORIGIN" "$MASTER_BRANCH" || \
die "Could not fetch $MASTER_BRANCH from $ORIGIN."
git fetch -q "$ORIGIN" "$DEVELOP_BRANCH" || \
git_do fetch -q "$ORIGIN" "$DEVELOP_BRANCH" || \
die "Could not fetch $DEVELOP_BRANCH from $ORIGIN."
fi
if has "$ORIGIN/$MASTER_BRANCH" $(git_remote_branches); then
Expand All @@ -276,9 +276,9 @@ cmd_finish() {
# in case a previous attempt to finish this release branch has failed,
# but the merge into master was successful, we skip it now
if ! git_is_branch_merged_into "$BRANCH" "$MASTER_BRANCH"; then
git checkout "$MASTER_BRANCH" || \
git_do checkout "$MASTER_BRANCH" || \
die "Could not check out $MASTER_BRANCH."
git merge --no-ff "$BRANCH" || \
git_do merge --no-ff "$BRANCH" || \
die "There were merge conflicts."
# TODO: What do we do now?
fi
Expand All @@ -294,7 +294,7 @@ cmd_finish() {
[ "$FLAGS_signingkey" != "" ] && opts="$opts -u '$FLAGS_signingkey'"
[ "$FLAGS_message" != "" ] && opts="$opts -m '$FLAGS_message'"
[ "$FLAGS_messagefile" != "" ] && opts="$opts -F '$FLAGS_messagefile'"
eval git tag $opts "$VERSION_PREFIX$VERSION" "$BRANCH" || \
eval git_do tag $opts "$VERSION_PREFIX$VERSION" "$BRANCH" || \
die "Tagging failed. Please run finish again to retry."
fi
fi
Expand All @@ -303,28 +303,28 @@ cmd_finish() {
# in case a previous attempt to finish this release branch has failed,
# but the merge into develop was successful, we skip it now
if ! git_is_branch_merged_into "$BRANCH" "$DEVELOP_BRANCH"; then
git checkout "$DEVELOP_BRANCH" || \
git_do checkout "$DEVELOP_BRANCH" || \
die "Could not check out $DEVELOP_BRANCH."

# TODO: Actually, accounting for 'git describe' pays, so we should
# ideally git merge --no-ff $tagname here, instead!
git merge --no-ff "$BRANCH" || \
git_do merge --no-ff "$BRANCH" || \
die "There were merge conflicts."
# TODO: What do we do now?
fi

# delete branch
if noflag keep; then
git branch -d "$BRANCH"
git_do branch -d "$BRANCH"
fi

if flag push; then
git push "$ORIGIN" "$DEVELOP_BRANCH" || \
git_do push "$ORIGIN" "$DEVELOP_BRANCH" || \
die "Could not push to $DEVELOP_BRANCH from $ORIGIN."
git push "$ORIGIN" "$MASTER_BRANCH" || \
git_do push "$ORIGIN" "$MASTER_BRANCH" || \
die "Could not push to $MASTER_BRANCH from $ORIGIN."
if noflag notag; then
git push --tags "$ORIGIN" || \
git_do push --tags "$ORIGIN" || \
die "Could not push tags to $ORIGIN."
fi
fi
Expand Down
28 changes: 14 additions & 14 deletions git-flow-init
Expand Up @@ -53,7 +53,7 @@ cmd_default() {
parse_args "$@"

if ! git rev-parse --git-dir >/dev/null 2>&1; then
git init
git_do init
else
# assure that we are not working in a repo with local changes
git_repo_is_headless || require_clean_working_tree
Expand Down Expand Up @@ -121,14 +121,14 @@ cmd_default() {
# name exists, checkout that branch and use it for master
if ! git_local_branch_exists "$master_branch" && \
git_remote_branch_exists "origin/$master_branch"; then
git branch "$master_branch" "origin/$master_branch" >/dev/null 2>&1
git_do branch "$master_branch" "origin/$master_branch" >/dev/null 2>&1
elif ! git_local_branch_exists "$master_branch"; then
die "Local branch '$master_branch' does not exist."
fi
fi

# store the name of the master branch
git config gitflow.branch.master "$master_branch"
git_do config gitflow.branch.master "$master_branch"
fi

# add a develop branch if no such branch exists yet
Expand Down Expand Up @@ -185,7 +185,7 @@ cmd_default() {
fi

# store the name of the develop branch
git config gitflow.branch.develop "$develop_branch"
git_do config gitflow.branch.develop "$develop_branch"
fi

# Creation of HEAD
Expand All @@ -194,8 +194,8 @@ cmd_default() {
# it to be able to create new branches.
local created_gitflow_branch=0
if ! git rev-parse --quiet --verify HEAD >/dev/null 2>&1; then
git symbolic-ref HEAD "refs/heads/$master_branch"
git commit --allow-empty --quiet -m "Initial commit"
git_do symbolic-ref HEAD "refs/heads/$master_branch"
git_do commit --allow-empty --quiet -m "Initial commit"
created_gitflow_branch=1
fi

Expand All @@ -213,9 +213,9 @@ cmd_default() {
# the develop branch now in that case (we base it on master, of course)
if ! git_local_branch_exists "$develop_branch"; then
if git_remote_branch_exists "origin/$develop_branch"; then
git branch "$develop_branch" "origin/$develop_branch" >/dev/null 2>&1
git_do branch "$develop_branch" "origin/$develop_branch" >/dev/null 2>&1
else
git branch --no-track "$develop_branch" "$master_branch"
git_do branch --no-track "$develop_branch" "$master_branch"
fi
created_gitflow_branch=1
fi
Expand All @@ -225,7 +225,7 @@ cmd_default() {

# switch to develop branch if its newly created
if [ $created_gitflow_branch -eq 1 ]; then
git checkout -q "$develop_branch"
git_do checkout -q "$develop_branch"
fi

# finally, ask the user for naming conventions (branch and tag prefixes)
Expand All @@ -251,7 +251,7 @@ cmd_default() {
printf "\n"
fi
[ "$answer" = "-" ] && prefix= || prefix=${answer:-$default_suggestion}
git config gitflow.prefix.feature "$prefix"
git_do config gitflow.prefix.feature "$prefix"
fi

# Release branches
Expand All @@ -264,7 +264,7 @@ cmd_default() {
printf "\n"
fi
[ "$answer" = "-" ] && prefix= || prefix=${answer:-$default_suggestion}
git config gitflow.prefix.release "$prefix"
git_do config gitflow.prefix.release "$prefix"
fi


Expand All @@ -278,7 +278,7 @@ cmd_default() {
printf "\n"
fi
[ "$answer" = "-" ] && prefix= || prefix=${answer:-$default_suggestion}
git config gitflow.prefix.hotfix "$prefix"
git_do config gitflow.prefix.hotfix "$prefix"
fi


Expand All @@ -292,7 +292,7 @@ cmd_default() {
printf "\n"
fi
[ "$answer" = "-" ] && prefix= || prefix=${answer:-$default_suggestion}
git config gitflow.prefix.support "$prefix"
git_do config gitflow.prefix.support "$prefix"
fi


Expand All @@ -306,7 +306,7 @@ cmd_default() {
printf "\n"
fi
[ "$answer" = "-" ] && prefix= || prefix=${answer:-$default_suggestion}
git config gitflow.prefix.versiontag "$prefix"
git_do config gitflow.prefix.versiontag "$prefix"
fi


Expand Down

2 comments on commit 15aab26

@LinboLen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curiosity. where is git_do command?

@LinboLen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

found in gitflow-common file

Please sign in to comment.