From: Wincent Colaiuta Date: Thu, 26 Mar 2009 09:59:59 GMT Subject: Re: Test that every revision builds before pushing changes? Message-ID: <35F1F494-E496-4126-92CC-79FD241D7BF3@wincent.com> In-Reply-To: <20090326094900.GC14292@coredump.intra.peff.net> El 26/3/2009, a las 10:49, Jeff King escribió: > On Thu, Mar 26, 2009 at 08:10:52PM +1100, Daniel Pittman wrote: > >> For example, the responsible person for that testing could use the >> hypothetical (until someone tells me where to find it): >> >> git test public..test make test >> >> Which would then effectively wrap: >> >> for each revision between public and private: >> git checkout revision >> make test >> # report if that fails, allow fixing the commit or whatever >> # then 'git test continue' to carry on... >> >> That turn the process from a manual one to an automated one: it runs >> that command for every revision until it fails, or until they all >> pass. > > I don't think such a script exists. There are continuous integration > systems that support git, but I don't know if they actually check > every > commit. It shouldn't be too hard to put together a script that does exactly what you want. A couple of years ago I whipped up a simple script (see below) to test all the commits on a topic branch before submitting them upstream. It's designed for that specific case, and I'm neither a shell nor a plumbing expert, but it worked for my simple workflow at least. Cheers, Wincent die () { echo "$1" exit 1 } git diff --quiet || die "Unstaged changes; won't start" git diff --cached --quiet || die "Staged changes; won't start" # parse HEAD (something like "ref: refs/heads/my_local_branch") to get remote and merge GIT_DIR=$(git rev-parse --git-dir) TOPIC="$GIT_DIR/HEAD" test -f "$TOPIC" || die "No HEAD found at '$TOPIC'" BRANCH_REF=$(< "$TOPIC") if [ "${BRANCH_REF%%: */*}" != "ref" ]; then die "expected HEAD '$BRANCH_REF' to be of the form 'ref: .../...'" fi BRANCH=${BRANCH_REF##*/} REMOTE=$(git config branch.$BRANCH.remote) || die "failed to get branch.$BRANCH.remote" MERGE=$(git config branch.$BRANCH.merge) || die "failed to get branch. $BRANCH.merge" MERGE=${MERGE##*/} # remember which branch we were on prior to starting trap 'git checkout $BRANCH' exit # will check all commits in topic branch not present in origin # (note: may be more appropriate to use "git merge-base" here) echo "On branch $BRANCH" echo "Commits to be checked:" git rev-list --pretty=oneline HEAD ^$REMOTE/$MERGE for COMMIT in $(git rev-list HEAD ^$REMOTE/$MERGE); do echo "Checking $COMMIT" git checkout $COMMIT make clean make test || die "Commit $COMMIT is bad (make test failed)" done echo "All revisions passed!"