Skip to content

Commit

Permalink
Cleaner git-fork code for github API call
Browse files Browse the repository at this point in the history
  • Loading branch information
techjacker committed Jan 23, 2017
1 parent 14ce977 commit bd407b6
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions bin/git-fork
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ fi
[ -z "$project" -o -z "$owner" ] && abort "github repo needs to be specified as an argument"

# create fork
curl_args="-qs -X POST -u $user"
curl_url="https://api.github.com/repos/$owner/$project/forks"
RES=$(curl -H "X-GitHub-OTP: $MFA_CODE" $curl_args "$curl_url")
curl -qs \
-X POST \
-u "$user" \
-H "X-GitHub-OTP: $MFA_CODE" \
"https://api.github.com/repos/$owner/$project/forks"

[ $? = 0 ] || abort "fork failed"

# Check if user has ssh configured with GitHub
Expand All @@ -45,13 +48,13 @@ fi

if [ "$origin" = true ]; then
git remote rename origin upstream
git remote add origin "$remote_prefix$user/${project}.git"
git remote add origin "${remote_prefix}${user}/${project}.git"
git fetch origin
else
# clone forked repo into current dir
git clone "$remote_prefix$user/${project}.git" "$project"
git clone "${remote_prefix}${user}/${project}.git" "$project"
# add reference to origin fork so can merge in upstream changes
cd "$project"
git remote add upstream "$remote_prefix$owner/${project}.git"
git remote add upstream "${remote_prefix}${owner}/${project}.git"
git fetch upstream
fi

0 comments on commit bd407b6

Please sign in to comment.