git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Test that every revision builds before pushing changes?

From
Wincent Colaiuta <win@wincent.com>
Date
Mar 26, 2009, 09:59 UTC
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ó:
Show 23 quoted lines
> 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!"
Previous: Jeff King
Message 7 of 7 in “Test that every revision builds before pushing changes?”
  1. Daniel PittmanMar 26, 2009
  2. Andreas EricssonMar 26, 2009
  3. Daniel PittmanMar 26, 2009
  4. Andreas EricssonMar 26, 2009
  5. Daniel PittmanMar 27, 2009
  6. Jeff KingMar 26, 2009
  7. Wincent ColaiutaMar 26, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.