# Set default values
force_push="0"
orig_branch=""
+remote=""
print_usage()
{
echo "Options:"
echo " -d debug mode"
echo " -p force push stacked branches (\"stack\" command)"
+ echo " -r set remote for tracking"
echo
}
fi
git checkout ${Q} -b ${dest_branch} ${src_branch}
+
+ if git config --get branch.$(git branch --show-current).remote 1> /dev/null; then
+ log_dbg "Remove existing tracking infos"
+ git branch --unset-upstream
+ fi
+
+ if [ "${remote}" != "" ]; then
+ if ! git ls-remote --exit-code ${remote} ${dest_branch} 1> /dev/null; then
+ # Git does not allow to set the upstream for a new branch if it
+ # doesn't already exist on the remote.
+
+ log_dbg "New remote branch (push): ${remote}/${dest_branch}"
+ # 2> >(grep -v "remote:" >&2):
+ # >(...): process substitution, creates a temporary pipe that behaves like a file
+ # grep -v "remote:": Filters stderr removing "remote:" lines to filter out github annoying pull messages
+ # >&2: Inside the substitution, sends the filtered results back to the original stderr
+ git push ${Q} ${remote} ${dest_branch} 2> >(grep -v "remote:" >&2)
+ else
+ log_dbg "Existing remote branch (set upstream): ${remote}/${dest_branch}"
+
+ # Set upstream tracking:
+ git branch ${Q} -u ${remote}/${dest_branch}
+ fi
+ fi
}
# Arg1: segment name
fi
}
-while getopts "dhp" flag ;do
+while getopts "dhpr:" flag ;do
case ${flag} in
d)
debug="1"
p)
force_push="1"
;;
+ r)
+ remote="${OPTARG}"
+ ;;
?)
log_err "${PROG_NAME}: Option invalide: ${OPTARG}."
exit 1