Re: Test that every revision builds before pushing changes?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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!"

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux