From 1d48bd7eafdbc93894836ac8e63d17b213bf70b0 Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Mon, 29 Sep 2008 03:17:14 -0500 Subject: [PATCH] First pass at sequential commit numbers. --- server/post-receive-assign-commit-numbers | 20 +++++++ ...rver-post-receive-assign-commit-numbers.sh | 57 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 server/post-receive-assign-commit-numbers create mode 100644 tests/t3200-server-post-receive-assign-commit-numbers.sh diff --git a/server/post-receive-assign-commit-numbers b/server/post-receive-assign-commit-numbers new file mode 100644 index 0000000..9d424b1 --- /dev/null +++ b/server/post-receive-assign-commit-numbers @@ -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 index 0000000..6e76cd6 --- /dev/null +++ b/tests/t3200-server-post-receive-assign-commit-numbers.sh @@ -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 + -- 2.39.5