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

[PATCHv2 6/6] t5543-atomic-push.sh: add basic tests for atomic pushes

From
Stefan Beller <sbeller@google.com>
Date
Dec 16, 2014, 18:49 UTC
Message-ID
<1418755747-22506-6-git-send-email-sbeller@google.com>
In-Reply-To
<1418755747-22506-1-git-send-email-sbeller@google.com>

This adds tests for the atomic push option. The first four tests check if the atomic option works in good conditions and the last three patches check if the atomic option prevents any change to be pushed if just one ref cannot be updated.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
Notes:
    Changes v1 -> v2:
    > Please drop unused comments; they are distracting.
    
    ok
    
    > It is not wrong per-se, but haven't you already tested in
    > combination with --mirror in the previous test?
    
    I fixed the previous tests, so that there is no --mirror
    and --atomic together. There is still a first --mirror push
    for setup and a second with --atomic <branchnames> though
    
    > check_branches upstream master HEAD@{2} second HEAD~
    
    A similar function test_ref_upstream is introduced.
    
    > What's the value of this test?  Isn't it a non-fast-forward check
    > you already tested in the previous one?
    
    I messed up there. Originally I wanted to test the 2 different
    stages of rejection. A non-fast-forward check is done locally and
    we don't even try pushing. But I also want to test if we locally
    thing all is good, but the server refuses a ref to update.
    This is now done with the last test named 'atomic push obeys
    update hook preventing a branch to be pushed'. And that still fails.
    
    I'll investigate that, while still sending out the series for another
    review though.
    
    * Redone the test helper, there is test_ref_upstream now.
      This tests explicitely for SHA1 values of the ref.
      (It's needed in the last test for example. The git push fails,
      but still modifies the ref :/ )
    * checked all && chains and repaired them
    * sometimes make use of git -C <workdir>
    
    Notes v1:
    Originally Ronnie had a similar patch prepared. But as I added
    more tests and cleaned up the existing tests (e.g. use test_commit
    instead of "echo one >file && gitadd file && git commit -a -m 'one'",
    removal of dead code), the file has changed so much that I'd rather
    take ownership.
 t/t5543-atomic-push.sh | 176 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 176 insertions(+)
 create mode 100755 t/t5543-atomic-push.sh
diff --git a/t/t5543-atomic-push.sh b/t/t5543-atomic-push.sh
new file mode 100755
index 0000000..6354fc0
--- /dev/null
+++ b/t/t5543-atomic-push.sh
@@ -0,0 +1,176 @@
+#!/bin/sh
+
+test_description='pushing to a repository using the atomic push option'
+
+. ./test-lib.sh
+
+D=`pwd`
+
+mk_repo_pair () {
+	rm -rf workbench upstream &&
+	test_create_repo upstream &&
+	test_create_repo workbench &&
+	(
+		cd upstream && git config receive.denyCurrentBranch warn
+	) &&
+	(
+		cd workbench && git remote add up ../upstream
+	)
+}
+
+# refname, expected value, e.g.
+# test_ref_upstream refs/heads/master HEADS{0}
+test_ref_upstream () {
+	test "$#" == "2" # if this fails, we have a bug in this script.
+	test "$(git -C upstream rev-parse --verify $1)" == "$2"
+}
+
+test_expect_success 'atomic push works for a single branch' '
+	mk_repo_pair &&
+	(
+		cd workbench &&
+		test_commit one &&
+		git push --mirror up &&
+		test_commit two &&
+		git push --atomic up master
+	) &&
+	test_ref_upstream master $(git -C workbench rev-parse --verify master)
+'
+
+test_expect_success 'atomic push works for two branches' '
+	mk_repo_pair &&
+	(
+		cd workbench &&
+		test_commit one &&
+		git branch second &&
+		git push --mirror up &&
+		test_commit two &&
+		git checkout second &&
+		test_commit three &&
+		git push --atomic up master second
+	) &&
+	test_ref_upstream master $(git -C workbench rev-parse --verify master) &&
+	test_ref_upstream second $(git -C workbench rev-parse --verify second)
+'
+
+test_expect_success 'atomic push works in combination with --mirror' '
+	mk_repo_pair &&
+	(
+		cd workbench &&
+		test_commit one &&
+		git checkout -b second &&
+		test_commit two &&
+		git push --atomic --mirror up
+	) &&
+	test_ref_upstream master $(git -C workbench rev-parse --verify master) &&
+	test_ref_upstream second $(git -C workbench rev-parse --verify second)
+'
+
+test_expect_success 'atomic push works in combination with --force' '
+	mk_repo_pair &&
+	(
+		cd workbench &&
+		test_commit one &&
+		git branch second master &&
+		test_commit two_a &&
+		git checkout second &&
+		test_commit two_b &&
+		test_commit three_b &&
+		test_commit four &&
+		git push --mirror up &&
+		# The actual test is below
+		git checkout master &&
+		test_commit three_a &&
+		git checkout second &&
+		git reset --hard HEAD^ &&
+		git push --force --atomic up master second
+	) &&
+	test_ref_upstream master $(git -C workbench rev-parse --verify master) &&
+	test_ref_upstream second $(git -C workbench rev-parse --verify second)
+'
+
+# set up two branches where master can be pushed but second can not
+# (non-fast-forward). Since second can not be pushed the whole operation
+# will fail and leave master untouched.
+test_expect_success 'atomic push fails if one branch fails' '
+	mk_repo_pair &&
+	(
+		cd workbench &&
+		test_commit one &&
+		git checkout -b second master &&
+		test_commit two &&
+		test_commit three &&
+		test_commit four &&
+		git push --mirror up &&
+		git reset --hard HEAD~2 &&
+		test_commit five &&
+		git checkout master &&
+		test_commit six &&
+		! git push --atomic --all up
+	) &&
+	test_ref_upstream master $(git -C workbench rev-parse --verify HEAD@{7}) &&
+	test_ref_upstream second $(git -C workbench rev-parse --verify HEAD@{4})
+'
+
+test_expect_success 'atomic push fails if one tag fails remotely' '
+	# prepare the repo
+	mk_repo_pair &&
+	(
+		cd workbench &&
+		test_commit one &&
+		git checkout -b second master &&
+		test_commit two &&
+		git push --mirror up
+	) &&
+	# a third party modifies the server side:
+	(
+		cd upstream &&
+		git checkout second &&
+		git tag test_tag second
+	) &&
+	# see if we can now push both branches.
+	(
+		cd workbench &&
+		git checkout master &&
+		test_commit three &&
+		git checkout second &&
+		test_commit four &&
+		git tag test_tag &&
+		test_must_fail git push --tags --atomic up master second
+	) &&
+	test_ref_upstream master $(git -C workbench rev-parse --verify HEAD@{3}) &&
+	test_ref_upstream second $(git -C workbench rev-parse --verify HEAD@{1})
+'
+
+test_expect_failure 'atomic push obeys update hook preventing a branch to be pushed' '
+	mk_repo_pair &&
+	(
+		cd workbench &&
+		test_commit one &&
+		git checkout -b second master &&
+		test_commit two &&
+		git push --mirror up
+	) &&
+	(
+		cd upstream &&
+		HOOKDIR="$(git rev-parse --git-dir)/hooks" &&
+		HOOK="$HOOKDIR/update" &&
+		mkdir -p "$HOOKDIR" &&
+		write_script "$HOOK" <<-\EOF
+			# only allow update to master from now on
+			test "$1" = "refs/heads/master"
+		EOF
+	) &&
+	(
+		cd workbench &&
+		git checkout master &&
+		test_commit three &&
+		git checkout second &&
+		test_commit four &&
+		test_must_fail git push --atomic up master second
+	) &&
+	test_ref_upstream master $(git -C workbench rev-parse --verify HEAD@{3}) &&
+	test_ref_upstream second $(git -C workbench rev-parse --verify HEAD@{1})
+'
+
+test_done
-- 
2.2.0.31.gad78000.dirty
Previous: Junio C HamanoNext: Stefan Beller
Message 27 of 56 in “Add a flag to push atomically”
  1. 0/5 Add a flag to push atomicallyStefan Beller, Dec 15, 2014
  2. 1/5 receive-pack.c: add protocol support to negotiate atomic-pushStefan Beller, Dec 15, 2014
  3. Junio C HamanoDec 15, 2014
  4. Stefan BellerDec 15, 2014
  5. 2/5 send-pack.c: add an --atomic-push command line argumentStefan Beller, Dec 15, 2014
  6. Junio C HamanoDec 15, 2014
  7. 3/5 receive-pack.c: use a single ref_transaction for atomic pushesStefan Beller, Dec 15, 2014
  8. Junio C HamanoDec 15, 2014
  9. 4/5 push.c: add an --atomic-push argumentStefan Beller, Dec 15, 2014
  10. Junio C HamanoDec 15, 2014
  11. 5/5 t5543-atomic-push.sh: add basic tests for atomic pushesStefan Beller, Dec 15, 2014
  12. Junio C HamanoDec 15, 2014
  13. Junio C HamanoDec 15, 2014
  14. 1/6 receive-pack.c: add protocol support to negotiate atomic-pushStefan Beller, Dec 16, 2014
  15. 2/6 send-pack: Invert the return value of ref_update_to_be_sentStefan Beller, Dec 16, 2014
  16. Junio C HamanoDec 16, 2014
  17. 3/6 send-pack.c: add --atomic command line argumentStefan Beller, Dec 16, 2014
  18. Junio C HamanoDec 16, 2014
  19. 4/6 receive-pack.c: use a single ref_transaction for atomic pushesStefan Beller, Dec 16, 2014
  20. Eric SunshineDec 16, 2014
  21. Eric SunshineDec 16, 2014
  22. Junio C HamanoDec 16, 2014
  23. 5/6 push.c: add an --atomic-push argumentStefan Beller, Dec 16, 2014
  24. Eric SunshineDec 16, 2014
  25. Junio C HamanoDec 16, 2014
  26. Junio C HamanoDec 16, 2014
  27. 6/6 t5543-atomic-push.sh: add basic tests for atomic pushesStefan Beller, Dec 16, 2014
  28. receive-pack: refuse all commands if one fails in atomic modeStefan Beller, Dec 16, 2014
  29. Junio C HamanoDec 16, 2014
  30. Eric SunshineDec 16, 2014
  31. Junio C HamanoDec 16, 2014
  32. Stefan BellerDec 16, 2014
  33. Junio C HamanoDec 16, 2014
  34. Stefan BellerDec 16, 2014
  35. Junio C HamanoDec 16, 2014
  36. Stefan BellerDec 16, 2014
  37. Junio C HamanoDec 16, 2014
  38. 0/6 atomic pushesStefan Beller, Dec 17, 2014
  39. 1/6 receive-pack.c: add protocol support to negotiate atomicStefan Beller, Dec 17, 2014
  40. Eric SunshineDec 19, 2014
  41. 2/6 send-pack: Rename ref_update_to_be_sent to check_to_send_updateStefan Beller, Dec 17, 2014
  42. Junio C HamanoDec 17, 2014
  43. 3/6 send-pack.c: add --atomic command line argumentStefan Beller, Dec 17, 2014
  44. Junio C HamanoDec 17, 2014
  45. Eric SunshineDec 19, 2014
  46. 4/6 receive-pack.c: use a single ref_transaction for atomic pushesStefan Beller, Dec 17, 2014
  47. Junio C HamanoDec 17, 2014
  48. Stefan BellerDec 17, 2014
  49. Junio C HamanoDec 18, 2014
  50. 4/6 receive-pack.c: use a single ref_transaction for atomic pushesStefan Beller, Dec 18, 2014
  51. Eric SunshineDec 18, 2014
  52. 4/6 receive-pack.c: use a single ref_transaction for atomic pushesStefan Beller, Dec 19, 2014
  53. Eric SunshineDec 19, 2014
  54. 5/6 push.c: add an --atomic argumentStefan Beller, Dec 17, 2014
  55. Eric SunshineDec 19, 2014
  56. 6/6 t5543-atomic-push.sh: add basic tests for atomic pushesStefan Beller, Dec 17, 2014

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.