[exim-dev] Git, Github, git-exim command

Startseite
Nachricht löschen
Nachricht beantworten
Autor: Phil Pennock
Datum:  
To: exim-dev
Betreff: [exim-dev] Git, Github, git-exim command
So we have this GitHub account for Exim. I didn't set it up, but I
think I'm the only one pushing changes to it.

I think GitHub is valuable: it provides decent fork/pull-request tools,
is familiar to a broader audience than our usual users, makes the code
more visible and gives us a managed infrastructure resilient to single
machine failures for making the code available, where tahini is just a
single box.

Not much has happened with the wiki, I was the one who got in Nigel's
way by creating fresh content there; perhaps we should blow that away
and programmatically migrate wiki.exim.org content?

Do we want to explore having a cron-job auto-sync content from tahini to
GitHub, or a post-receive-hook or the like on tahini to auto-push to
GitHub?


FWIW, here's my "git-exim" shell script. It goes into a directory in
$PATH and then I have "git exim" as a command. "push_origins" and
"push_ssh_key_fp_re" need to be customised (and could probably do with
making use of any git config framework, to be settable in ~/.gitconfig).

"git exim push-all" pushes master to all the repos in $push_origins, and
takes an optional branch to push that branch to all repos instead.

"git setconfig" invokes an external command I have elsewhere, which
manipulates a new checkout's .git/config file to set things like the
email address used to be my exim.org one instead; that's not included
here, it's too buggy and fragile to promote.

So yes, "push-all" is the only current sub-command. It's useful enough
to me that I'm bothering to share this, as part of the discussion around
repository maintenance.

-Phil
#!/bin/sh

push_origins="origin pdp-tahini spodhuis github"
push_ssh_key_fp_re="(?x)
  (?:
    (?: 1c:fc:c6:62:63:77:17:9c:8c:70:9f:4b:b8:2f:c5:bd ) |
    (?: 89:3e:fe:96:33:bf:c9:fb:66:93:54:9b:ec:53:47:45 ) |
    (?: 5f:ef:7b:6c:97:4e:8a:ec:01:87:b6:a9:e0:34:2e:3d )
  )"


USAGE="push-all [<branch>]
or: setconfig"

SUBDIRECTORY_OK=true

. "$(git --exec-path)/git-sh-setup"

# have $GIT_DIR and $GIT_OBJECT_DIRECTORY plus $GIT_QUIET

[ -d /opt/local/bin ] && PATH="/opt/local/bin:$PATH"

set -e

have_valid_push_ssh() {
    ssh-add -l | pcregrep -q "$push_ssh_key_fp_re"
}


# When pushing, be able to push through branches, etc
#
cmd_push_all() {
    local Remote


    have_valid_push_ssh || die "Missing valid SSH keys?"


    for Remote in $push_origins
    do
        if git config --get "remote.${Remote}.url" >/dev/null 2>&1
        then
            echo >&2 "Pushing to: $Remote"
            git push "$Remote" "$@"
        else
            echo "Remote not defined, skipping: $Remote"
        fi
    done
}


cmd_setconfig() {
    git_exim_setconfig "$@"
}


command=
opt_parse=:

while [ $# -gt 0 ] && [ -z "$command" ]
do
    case "$1" in
    push-all)
        command="push_all"
        ;;
    setconfig)
        command="setconfig"
        ;;
    --) opt_parse=false ;;
    -*)
        if $opt_parse; then
            die "Unknown option: $1"
        fi
        # is not an option, but a param, and still unknown if in this loop
        ;;
    *)
        usage; break ;;
    esac
    shift
done


[ -z "$command" ] && usage

require_work_tree
require_work_tree_exists
cd_to_toplevel

"cmd_$command" "$@"