mirror of
https://github.com/tj/git-extras.git
synced 2026-09-15 09:56:19 -04:00
add upstream check & bugfix
This commit is contained in:
parent
19ece6192e
commit
f0ecd82129
14
bin/git-sync
14
bin/git-sync
|
|
@ -44,16 +44,20 @@ function main()
|
|||
shift
|
||||
done
|
||||
|
||||
local remote_branch
|
||||
if [ "${remote}" = "" ]; then
|
||||
local remote_branch="$(git rev-parse --abbrev-ref --symbolic-full-name @{u})"
|
||||
branch="$(git rev-parse --abbrev-ref --symbolic-full-name @)"
|
||||
remote="${remote_branch%%/${branch}}"
|
||||
if ! remote_branch="$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null)"; then
|
||||
echo "There is no upstream information of local branch."
|
||||
exit 1
|
||||
fi
|
||||
local branch="$(git rev-parse --abbrev-ref --symbolic-full-name @)"
|
||||
local remote=$(git config "branch.${branch}.remote")
|
||||
elif [ "${branch}" = "" ]; then
|
||||
echo -e "Error: too few arguments.\n"
|
||||
_usage
|
||||
exit 1
|
||||
else
|
||||
local remote_branch="${remote}/${branch}"
|
||||
remote_branch="${remote}/${branch}"
|
||||
fi
|
||||
|
||||
echo "Are you sure you want to clean all changes & sync with '${remote_branch}'? [y/N]"
|
||||
|
|
@ -61,7 +65,7 @@ function main()
|
|||
read res
|
||||
case "${res}" in
|
||||
"Y" | "y" | "yes" | "Yes" | "YES" )
|
||||
echo "git fetch "${remote}" "${branch}" && git reset --hard "${remote_branch}" && git clean -d -f -x"
|
||||
git fetch "${remote}" "${branch}" && git reset --hard "${remote_branch}" && git clean -d -f -x
|
||||
;;
|
||||
* )
|
||||
echo "Canceled."
|
||||
|
|
|
|||
Loading…
Reference in a new issue