]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - sync.sh
5745ae57215f7471a897a3f44b3d25fc8f0926b1
[config/dotfiles.git] / sync.sh
1 #!/bin/sh
2
3 # Syncs with remote hosts in the git (sub)directories.
4 #
5 # Allows fetching (no merge) and pushing at the moment.
6
7
8 # Select the method: fetch, push and status is possible.
9 if [ x$1 = x -o x$1 = xfetch -o x$1 = xfe ]; then
10     method=fetch
11 elif [ $1 = push -o $1 = pu ]; then
12     method=push
13 elif [ $1 = status -o $1 = st ]; then
14     method=status
15 else
16     echo "Usage: sync.sh [fetch | fe | push | pu | status | st]"
17     echo
18     echo "fetch: Fetch from all remotes."
19     echo "push: Push to all remotes."
20     echo "status: Display status for all git repositories."
21     exit 1
22 fi
23
24 # Execute the given method for each git subdirectory.
25 for project in `find . -name .git -type d`; do
26     pwd=`pwd`
27     cd "$project"
28
29     # Remove .git from repository name.
30     project=`echo "$project" | sed "s|.git||"`
31
32     # Display all commits not in the master branch.
33     if [ $method = status ]; then
34         echo "status of $project"
35         git log --graph --all --pretty=oneline master..
36     # Fetch from/Push to all remotes.
37     else
38         for remote in `git remote`; do
39             echo "$project: ${method}ing $remote ..."
40             git $method "$remote"
41         done
42     fi
43
44     cd "$pwd"
45 done