Skip to content
Newer
Older
100755 58 lines (48 sloc) 1.83 KB
58dcade @jamiew Basic 'push' command for completeness. I'm stoked for the clipboard f…
authored Jan 24, 2011
1 #!/bin/sh
32e7bec @jamiew push: --set-upstream while pushing (same as -u)
authored May 25, 2011
2 #
58dcade @jamiew Basic 'push' command for completeness. I'm stoked for the clipboard f…
authored Jan 25, 2011
3 # Usage: push
4 #
5daed4f @jamiew Cleanup commentary
authored Jan 25, 2011
5 # Send your local branch changes to the remote branch,
6 # and copy the relevant GitHub 'compare' URL to your clipboard (!)
7 # This is Mac-only for the time being
b67805d @jamiew push: extra args will be passed through, e.g. 'push -f'
authored Feb 18, 2011
8 #
9 # Any extra args to this command will be passed through to 'git push',
10 # e.g. for doing "push -f"
32e7bec @jamiew push: --set-upstream while pushing (same as -u)
authored May 25, 2011
11 #
58dcade @jamiew Basic 'push' command for completeness. I'm stoked for the clipboard f…
authored Jan 25, 2011
12
b4caca5 @jamiew Cleanup
authored Feb 8, 2012
13 # TODO DRY this b/w pull and push
bc92dbd @jamiew Add support for non-origin remotes to push & pull
authored Feb 8, 2012
14 branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') || exit $?
b4caca5 @jamiew Cleanup
authored Feb 8, 2012
15 default_remote="origin"
16 remote=$(git config "branch.${branch}.remote" || echo "$default_remote")
17 remote_branch=$( (git config "branch.${branch}.merge" || echo "refs/heads/$branch") | awk -F '/' '{ print $3 }' )
18
19 echo "branch=$branch remote=$remote/$remote_branch"
58dcade @jamiew Basic 'push' command for completeness. I'm stoked for the clipboard f…
authored Jan 25, 2011
20
1524355 @jamiew Pimp out push for clipboard action
authored Jan 25, 2011
21 # Push & save output
bc92dbd @jamiew Add support for non-origin remotes to push & pull
authored Feb 8, 2012
22 push=$(git push --set-upstream $* $remote $remote_branch 2>&1)
1524355 @jamiew Pimp out push for clipboard action
authored Jan 25, 2011
23 exit_code=$?
5845bf2 @jamiew Maintenance: whitespace, comments, general cleanup
authored Aug 21, 2011
24
1524355 @jamiew Pimp out push for clipboard action
authored Jan 25, 2011
25 if [ $exit_code != 0 ]; then
26 echo "Ouch, push failed! code=$exit_code, output=$push"
27 exit $exit_code
9a1b42e @jamiew push: proper compare URLs for newly pushed branches
authored Jun 30, 2011
28 elif echo $push | grep "Everything up-to-date" >/dev/null; then
29 echo "git says everything is up-to-date!"
1524355 @jamiew Pimp out push for clipboard action
authored Jan 25, 2011
30 exit 0
31 fi
32
9a1b42e @jamiew push: proper compare URLs for newly pushed branches
authored Jun 30, 2011
33 # Parse relevant commit refs and let user know what we did
34 # 1st-time push to new branch gets special treatment
78f962a @jamiew Escape brackets correctly
authored Jun 30, 2011
35 if echo $push | grep "\[new branch\]" >/dev/null; then
9a1b42e @jamiew push: proper compare URLs for newly pushed branches
authored Jun 30, 2011
36 refs="master...$branch"
37 echo "Pushed new branch '$branch' remotely"
38 else
39 refs=$(echo $push | awk '{ print $3}' | sed 's/\.\./\.\.\./')
40 echo $push
41 fi
579fdd8 @jamiew push: smarter pbcopy command detection, cleaner output
authored Feb 17, 2011
42
9a1b42e @jamiew push: proper compare URLs for newly pushed branches
authored Jun 30, 2011
43 # Parse output into a sexy GitHub compare URL!
3b50193 @jamiew Fully pimped push command, featuring smart GitHub clipboard-copy URL
authored Jan 25, 2011
44 remote_url=$(git remote show $remote -n | grep Push | awk '{ print $3 }')
9a5e199 @jamiew Fix if/not if
authored Feb 26, 2011
45 if [[ "$remote_url" =~ "github.com" ]]; then
1524355 @jamiew Pimp out push for clipboard action
authored Jan 25, 2011
46
9a1b42e @jamiew push: proper compare URLs for newly pushed branches
authored Jun 30, 2011
47 repo_name=$(echo $remote_url | sed 's/.*\:\(.*\)\.git/\1/')
fc39ebd @jamiew push: only copy GitHub compare url if remote is on GitHub
authored Feb 26, 2011
48 github_url="https://github.com/$repo_name/compare/$refs"
57b8d42 @mmalecki push: make clipboard copying work in Linux
mmalecki authored Sep 27, 2011
49 copied="Compare URL copied to clipboard!"
b4caca5 @jamiew Cleanup
authored Feb 8, 2012
50 which pbcopy >& /dev/null && echo $github_url | pbcopy && echo $copied
57b8d42 @mmalecki push: make clipboard copying work in Linux
mmalecki authored Sep 27, 2011
51 which xclip >& /dev/null && echo $github_url | xclip -selection clipboard && echo $copied
3b50193 @jamiew Fully pimped push command, featuring smart GitHub clipboard-copy URL
authored Jan 25, 2011
52
5845bf2 @jamiew Maintenance: whitespace, comments, general cleanup
authored Aug 22, 2011
53 echo $github_url
fc39ebd @jamiew push: only copy GitHub compare url if remote is on GitHub
authored Feb 27, 2011
54 echo
55 fi
5845bf2 @jamiew Maintenance: whitespace, comments, general cleanup
authored Aug 22, 2011
56
57b8d42 @mmalecki push: make clipboard copying work in Linux
mmalecki authored Sep 27, 2011
57 exit 0
Something went wrong with that request. Please try again.