aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/git
diff options
context:
space:
mode:
Diffstat (limited to 'bin/git')
-rwxr-xr-xbin/git/check-repos.sh48
-rwxr-xr-xbin/git/swap-protocol.bash25
2 files changed, 73 insertions, 0 deletions
diff --git a/bin/git/check-repos.sh b/bin/git/check-repos.sh
new file mode 100755
index 0000000..5180fc9
--- /dev/null
+++ b/bin/git/check-repos.sh
@@ -0,0 +1,48 @@
1#! /bin/bash
2
3LIST=~/.repos
4[[ $1 == -n ]] && {
5 COUNT_ONLY=true
6 count=0
7}
8
9
10# Only works when file ~/.repos exists and readable
11if [ ! -r $LIST ]; then
12 echo File ~/.repos not found/readable
13 exit 1
14fi
15
16
17while read repo remote; do
18 [[ "$repo" =~ ^[[:space:]]*#.* ]] && continue
19
20 # In case repo is consists of variable like $HOME
21 # Use eval to get git information
22 eval cd $repo 2>/dev/null || {
23 echo Repo $repo is inaccessible
24 exit 1
25 }
26
27 # Changes in working dir, not yet to be a commit
28 changes="$(git -c color.status=always status --short)"
29
30 # Diff between from local repo and remote
31 cherry="$([ -n "`git remote`" ] && git cherry)"
32
33 if [[ $COUNT_ONLY == true ]]; then
34 # If '-n' is specified, only count repo with changes/local-diff
35 [[ -n "$changes" || -n "$cherry" ]] && (( count++ ))
36 else
37 # Or, just print their status
38 echo Check $repo
39 [[ -n "$changes" ]] && echo "$changes"
40 [[ -n "$cherry" ]] && echo -e "\e[31m[ahead]\e[0m"
41 fi
42done <$LIST
43
44
45# If '-n' is specified, print number of repos with changes/local-diff
46[[ $COUNT_ONLY == true ]] && echo $count
47
48exit 0
diff --git a/bin/git/swap-protocol.bash b/bin/git/swap-protocol.bash
new file mode 100755
index 0000000..b7f4db2
--- /dev/null
+++ b/bin/git/swap-protocol.bash
@@ -0,0 +1,25 @@
1#! /usr/bin/env bash
2# Get the first remote URL within git/https protocol on github.com
3# Swap the protocol, and apply new protocol to every remaining remotes
4
5target=''
6extra=''
7
8# For each remote
9git remote -v \
10| while read remote url etc; do
11 # Set fetch/push URL seperately
12 [[ $etc =~ push ]] && extra='--push' || extra=''
13
14 if [[ $url =~ git@.*github.com ]]; then
15 target=${target:-https}
16 # git@ -> https://
17 [[ $target == https ]] && sed -E 's#^git@(.+):(.+)$#https://\1/\2#' <<<$url | xargs git remote set-url $extra $remote
18 elif [[ $url =~ https://.*github.com ]]; then
19 target=${target:-git}
20 # https:// -> git@
21 [[ $target == git ]] && sed -E 's#^https://([^/]+)/(.+)$#git@\1:\2#' <<<$url | xargs git remote set-url $extra $remote
22 fi
23done
24
25git remote -v