@@ -1543,3 +1543,104 @@ def test_bump_get_next__no_eligible_commits_raises(mocker: MockFixture):
15431543
15441544 with pytest.raises(NoneIncrementExit):
15451545 cli.main()
1546+
1547+
1548+ def test_bump_allow_no_commit_with_no_commit(mocker, tmp_commitizen_project, capsys):
1549+ with tmp_commitizen_project.as_cwd():
1550+ # Create the first commit and bump to 1.0.0
1551+ create_file_and_commit("feat(user)!: new file")
1552+ testargs = ["cz", "bump", "--yes"]
1553+ mocker.patch.object(sys, "argv", testargs)
1554+ cli.main()
1555+
1556+ # Verify NoCommitsFoundError should be raised
1557+ # when there's no new commit and "--allow-no-commit" is not set
1558+ with pytest.raises(NoCommitsFoundError):
1559+ testargs = ["cz", "bump"]
1560+ mocker.patch.object(sys, "argv", testargs)
1561+ cli.main()
1562+
1563+ # bump to 1.0.1 with new commit when "--allow-no-commit" is set
1564+ testargs = ["cz", "bump", "--allow-no-commit"]
1565+ mocker.patch.object(sys, "argv", testargs)
1566+ cli.main()
1567+ out, _ = capsys.readouterr()
1568+ assert "bump: version 1.0.0 → 1.0.1" in out
1569+
1570+
1571+ def test_bump_allow_no_commit_with_no_eligible_commit(
1572+ mocker, tmp_commitizen_project, capsys
1573+ ):
1574+ with tmp_commitizen_project.as_cwd():
1575+ # Create the first commit and bump to 1.0.0
1576+ create_file_and_commit("feat(user)!: new file")
1577+ testargs = ["cz", "bump", "--yes"]
1578+ mocker.patch.object(sys, "argv", testargs)
1579+ cli.main()
1580+
1581+ # Create a commit that is ineligible to bump
1582+ create_file_and_commit("docs(bump): add description for allow no commit")
1583+
1584+ # Verify NoneIncrementExit should be raised
1585+ # when there's no eligible bumping commit and "--allow-no-commit" is not set
1586+ with pytest.raises(NoneIncrementExit):
1587+ testargs = ["cz", "bump", "--yes"]
1588+ mocker.patch.object(sys, "argv", testargs)
1589+ cli.main()
1590+
1591+ # bump to 1.0.1 with ineligible commit when "--allow-no-commit" is set
1592+ testargs = ["cz", "bump", "--allow-no-commit"]
1593+ mocker.patch.object(sys, "argv", testargs)
1594+ cli.main()
1595+ out, _ = capsys.readouterr()
1596+ assert "bump: version 1.0.0 → 1.0.1" in out
1597+
1598+
1599+ def test_bump_allow_no_commit_with_increment(mocker, tmp_commitizen_project, capsys):
1600+ with tmp_commitizen_project.as_cwd():
1601+ # # Create the first commit and bump to 1.0.0
1602+ create_file_and_commit("feat(user)!: new file")
1603+ testargs = ["cz", "bump", "--yes"]
1604+ mocker.patch.object(sys, "argv", testargs)
1605+ cli.main()
1606+
1607+ # Verify NoCommitsFoundError should be raised
1608+ # when there's no new commit and "--allow-no-commit" is not set
1609+ with pytest.raises(NoCommitsFoundError):
1610+ testargs = ["cz", "bump", "--yes"]
1611+ mocker.patch.object(sys, "argv", testargs)
1612+ cli.main()
1613+
1614+ # bump to 1.1.0 with no new commit when "--allow-no-commit" is set
1615+ # and increment is specified
1616+ testargs = ["cz", "bump", "--yes", "--allow-no-commit", "--increment", "MINOR"]
1617+ mocker.patch.object(sys, "argv", testargs)
1618+ cli.main()
1619+ out, _ = capsys.readouterr()
1620+ assert "bump: version 1.0.0 → 1.1.0" in out
1621+
1622+
1623+ def test_bump_allow_no_commit_with_manual_version(
1624+ mocker, tmp_commitizen_project, capsys
1625+ ):
1626+ with tmp_commitizen_project.as_cwd():
1627+ # # Create the first commit and bump to 1.0.0
1628+ create_file_and_commit("feat(user)!: new file")
1629+ testargs = ["cz", "bump", "--yes"]
1630+ mocker.patch.object(sys, "argv", testargs)
1631+ cli.main()
1632+
1633+ # Verify NoCommitsFoundError should be raised
1634+ # when there's no new commit and "--allow-no-commit" is not set
1635+ with pytest.raises(NoCommitsFoundError):
1636+ testargs = ["cz", "bump", "--yes"]
1637+ mocker.patch.object(sys, "argv", testargs)
1638+ cli.main()
1639+
1640+ # bump to 1.1.0 with no new commit when "--allow-no-commit" is set
1641+ # and increment is specified
1642+ testargs = ["cz", "bump", "--yes", "--allow-no-commit", "2.0.0"]
1643+ mocker.patch.object(sys, "argv", testargs)
1644+ cli.main()
1645+ out, _ = capsys.readouterr()
1646+ assert "bump: version 1.0.0 → 2.0.0" in out
0 commit comments