First pass at sequential commit numbers.
authorStephen Haberman <stephen@exigencecorp.com>
Mon, 29 Sep 2008 08:17:14 +0000 (03:17 -0500)
committerStephen Haberman <stephen@exigencecorp.com>
Mon, 29 Sep 2008 08:17:14 +0000 (03:17 -0500)
server/post-receive-assign-commit-numbers [new file with mode: 0644]
tests/t3200-server-post-receive-assign-commit-numbers.sh [new file with mode: 0644]

diff --git a/server/post-receive-assign-commit-numbers b/server/post-receive-assign-commit-numbers
new file mode 100644 (file)
index 0000000..9d424b1
--- /dev/null
@@ -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
+
diff --git a/tests/t3200-server-post-receive-assign-commit-numbers.sh b/tests/t3200-server-post-receive-assign-commit-numbers.sh
new file mode 100644 (file)
index 0000000..6e76cd6
--- /dev/null
@@ -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
+