Permalink
Browse files

First pass at sequential commit numbers.

  • Loading branch information...
1 parent 2b6908d commit 1d48bd7eafdbc93894836ac8e63d17b213bf70b0 @stephenh committed Sep 29, 2008
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+. $(dirname $0)/functions
+
+while read oldrev newrev refname ; do
+ set_new_commits
+ echo "$new_commits" | git rev-list --reverse --stdin | while read commit ; do
+ cat $GIT_DIR/packed-refs | grep --quiet "$commit"
+ if [ $? -ne 0 ] ; then
+ current=$(cat $GIT_DIR/packed-refs | grep "refs/tags/r/" | tail -n 1 | grep -oP "r\/\d+" | grep -oP "\d+")
+ if [ $? -ne 0 ] ; then
+ next="0"
+ else
+ next=$(($current + 1))
+ fi
+ echo "$commit refs/tags/r/$next" >> $GIT_DIR/packed-refs
+ fi
+ done
+done
+
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+test_description='server assign commit numbers'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+ echo "setup" >a &&
+ git add a &&
+ git commit -m "setup" &&
+ git clone ./. server &&
+ rm -fr server/.git/hooks &&
+ git remote add origin ./server &&
+ git config --add branch.master.remote origin &&
+ git config --add branch.master.merge refs/heads/master &&
+ git fetch
+'
+
+install_post_receive_hook 'post-receive-assign-commit-numbers'
+
+test_expect_success 'assign one new commit' '
+ git checkout master &&
+ echo "$test_name" >a &&
+ git commit -a -m "changed a" &&
+ git push origin master &&
+ git fetch &&
+
+ test "$(git rev-parse HEAD)" = "$(git rev-parse r/0)"
+ test "$(git describe --tags)" = "r/0"
+'
+
+test_expect_success 'assign two new commits' '
+ echo "$test_name first" >a &&
+ git commit -a -m "changed a first" &&
+ echo "$test_name second" >a &&
+ git commit -a -m "changed a second" &&
+ git push origin master &&
+ git fetch &&
+
+ test "$(git rev-parse HEAD)" = "$(git rev-parse r/2)"
+ test "$(git describe --tags)" = "r/2"
+
+ test "$(git rev-parse HEAD^)" = "$(git rev-parse r/1)"
+ test "$(git describe --tags HEAD^)" = "r/1"
+'
+
+test_expect_success 'pushing commits to a new branch does not reassign' '
+ git checkout -b topica &&
+ echo "$test_name" &&
+ git push origin topica &&
+ git fetch &&
+
+ ! git rev-parse r/3
+'
+
+test_done
+

0 comments on commit 1d48bd7

Please sign in to comment.