mathyoudawson: Hi @RobertKirk,
Apologies for the basic formatting errors -  I have fixed them in the latest fixup commit.
RobertKirk: No worries. Looks good now, will squash and merge.
diff --git a/README.md b/README.md
index bbcb532..27ee749 100644
--- a/README.md
+++ b/README.md
@@ -87,6 +87,8 @@ optional arguments:
                            [env var: MARGE_ADD_TESTED] (default: False)
   --batch               Enable processing MRs in batches
                            [env var: MARGE_BATCH] (default: False)
+  --use-no-ff-batches      Disable fast forwarding when merging MR batches.
+                           [env var: MARGE_USE_NO_FF_BATCHES] (default: False)
   --add-part-of         Add "Part-of: <$MR_URL>" to each commit in MR.
                            [env var: MARGE_ADD_PART_OF] (default: False)
   --add-reviewers       Add "Reviewed-by: $approver" for each approver of MR to each commit in MR.
diff --git a/marge/app.py b/marge/app.py
index 0748643..a991811 100644
--- a/marge/app.py
+++ b/marge/app.py
@@ -208,6 +208,11 @@ def _parse_config(args):
         action='store_true',
         help='Debug logging (includes all HTTP requests etc).\n',
     )
+    parser.add_argument(
+        '--use-no-ff-batches',
+        action='store_true',
+        help='Disable fast forwarding when merging MR batches'
+    )
     config = parser.parse_args(args)
 
     if config.use_merge_strategy and config.batch:
diff --git a/marge/batch_job.py b/marge/batch_job.py
index b99fd87..2f4cae8 100644
--- a/marge/batch_job.py
+++ b/marge/batch_job.py
@@ -108,6 +108,19 @@ class BatchMergeJob(MergeJob):
             if getattr(changed_mr, attr) != getattr(merge_request, attr):
                 raise CannotMerge(error_message.format(attr.replace('_', ' ')))
 
+    def merge_batch(self, target_branch, source_branch, no_ff=False):
+        if no_ff:
+            return self._repo.merge(
+                    target_branch,
+                    source_branch,
+                    '--no-ff',
+            )
+
+        return self._repo.fast_forward(
+            target_branch,
+            source_branch,
+        )
+
     def accept_mr(
         self,
         merge_request,
@@ -142,9 +155,10 @@ class BatchMergeJob(MergeJob):
         self.maybe_reapprove(merge_request, approvals)
 
         # This switches git to <target_branch>
-        final_sha = self._repo.fast_forward(
+        final_sha = self.merge_batch(
             merge_request.target_branch,
             merge_request.source_branch,
+            self._options.use_no_ff_batches,
         )
 
         # Don't force push in case the remote has changed.

When merging batches, fast fordwarding is enabled
Fast forward only is enabled when merging batches. This is problematic as when reverting a change included in a batch, every commit associated with the change must be reverted rather than just the merge commit.

There should be some configuration so that fast-forwarding can be disabled when merging batches.

https://github.com/smarkets/marge-bot/blob/master/marge/batch_job.py#L145
diff --git a/tests/test_batch_job.py b/tests/test_batch_job.py
index 109b905..4ac2c5b 100644
--- a/tests/test_batch_job.py
+++ b/tests/test_batch_job.py
@@ -138,6 +138,28 @@ class TestBatchJob:
             force=True,
         )
 
+    def test_merge_batch(self, api, mocklab):
+        batch_merge_job = self.get_batch_merge_job(api, mocklab)
+        target_branch = 'master'
+        source_branch = mocklab.merge_request_info['source_branch']
+        batch_merge_job.merge_batch(target_branch, source_branch, no_ff=False)
+        batch_merge_job._repo.fast_forward.assert_called_once_with(
+            target_branch,
+            source_branch,
+        )
+
+    def test_merge_batch_with_no_ff_enabled(self, api, mocklab):
+        batch_merge_job = self.get_batch_merge_job(api, mocklab)
+        target_branch = 'master'
+        source_branch = mocklab.merge_request_info['source_branch']
+        batch_merge_job.merge_batch(target_branch, source_branch, no_ff=True)
+        batch_merge_job._repo.merge.assert_called_once_with(
+            target_branch,
+            source_branch,
+            '--no-ff'
+        )
+        batch_merge_job._repo.fast_forward.assert_not_called()
+
     def test_ensure_mr_not_changed(self, api, mocklab):
         with patch('marge.batch_job.MergeRequest') as mr_class:
             batch_merge_job = self.get_batch_merge_job(api, mocklab)

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest
3.9
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
astroid==3.3.9
certifi==2025.1.31
charset-normalizer==3.4.1
ConfigArgParse==1.7
coverage==7.8.0
dateparser==1.2.1
dill==0.3.9
exceptiongroup==1.2.2
flake8==7.2.0
humanize==4.12.2
idna==3.10
iniconfig==2.1.0
isort==6.0.1
-e git+https://github.com/smarkets/marge-bot.git@5de1f8cc465630e97f5d419521c6b5becef52afe#egg=marge
maya==0.6.1
mccabe==0.7.0
packaging==24.2
pendulum==3.0.0
platformdirs==4.3.7
pluggy==1.5.0
pycodestyle==2.13.0
pyflakes==3.3.1
pylint==3.3.6
pytest==8.3.5
pytest-cov==6.0.0
pytest-flake8==1.3.0
pytest-pylint==0.21.0
pytest-runner==6.0.1
python-dateutil==2.9.0.post0
pytz==2025.2
PyYAML==6.0.2
regex==2024.11.6
requests==2.32.3
six==1.17.0
snaptime==0.2.4
time-machine==2.16.0
tomli==2.2.1
tomlkit==0.13.2
typing_extensions==4.13.0
tzdata==2025.2
tzlocal==5.3.1
urllib3==2.3.0

name: marge-bot
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - astroid==3.3.9
      - certifi==2025.1.31
      - charset-normalizer==3.4.1
      - configargparse==1.7
      - coverage==7.8.0
      - dateparser==1.2.1
      - dill==0.3.9
      - exceptiongroup==1.2.2
      - flake8==7.2.0
      - humanize==4.12.2
      - idna==3.10
      - iniconfig==2.1.0
      - isort==6.0.1
      - maya==0.6.1
      - mccabe==0.7.0
      - packaging==24.2
      - pendulum==3.0.0
      - platformdirs==4.3.7
      - pluggy==1.5.0
      - pycodestyle==2.13.0
      - pyflakes==3.3.1
      - pylint==3.3.6
      - pytest==8.3.5
      - pytest-cov==6.0.0
      - pytest-flake8==1.3.0
      - pytest-pylint==0.21.0
      - pytest-runner==6.0.1
      - python-dateutil==2.9.0.post0
      - pytz==2025.2
      - pyyaml==6.0.2
      - regex==2024.11.6
      - requests==2.32.3
      - six==1.17.0
      - snaptime==0.2.4
      - time-machine==2.16.0
      - tomli==2.2.1
      - tomlkit==0.13.2
      - typing-extensions==4.13.0
      - tzdata==2025.2
      - tzlocal==5.3.1
      - urllib3==2.3.0
prefix: /opt/conda/envs/marge-bot

tests/test_batch_job.py::TestBatchJob::test_merge_batch[True] tests/test_batch_job.py::TestBatchJob::test_merge_batch[False] tests/test_batch_job.py::TestBatchJob::test_merge_batch_with_no_ff_enabled[True] tests/test_batch_job.py::TestBatchJob::test_merge_batch_with_no_ff_enabled[False]
tests/test_batch_job.py::PYLINT
tests/test_batch_job.py::flake-8::FLAKE8 tests/test_batch_job.py::TestBatchJob::test_remove_batch_branch[True] tests/test_batch_job.py::TestBatchJob::test_remove_batch_branch[False] tests/test_batch_job.py::TestBatchJob::test_close_batch_mr[True] tests/test_batch_job.py::TestBatchJob::test_close_batch_mr[False] tests/test_batch_job.py::TestBatchJob::test_create_batch_mr[True] tests/test_batch_job.py::TestBatchJob::test_create_batch_mr[False] tests/test_batch_job.py::TestBatchJob::test_get_mrs_with_common_target_branch[True] tests/test_batch_job.py::TestBatchJob::test_get_mrs_with_common_target_branch[False] tests/test_batch_job.py::TestBatchJob::test_ensure_mergeable_mr_ci_not_ok[True] tests/test_batch_job.py::TestBatchJob::test_ensure_mergeable_mr_ci_not_ok[False] tests/test_batch_job.py::TestBatchJob::test_push_batch[True] tests/test_batch_job.py::TestBatchJob::test_push_batch[False] tests/test_batch_job.py::TestBatchJob::test_ensure_mr_not_changed[True] tests/test_batch_job.py::TestBatchJob::test_ensure_mr_not_changed[False] tests/test_batch_job.py::TestBatchJob::test_fuse_mr_when_target_branch_was_moved[True] tests/test_batch_job.py::TestBatchJob::test_fuse_mr_when_target_branch_was_moved[False] tests/test_batch_job.py::TestBatchJob::test_fuse_mr_when_source_branch_was_moved[True] tests/test_batch_job.py::TestBatchJob::test_fuse_mr_when_source_branch_was_moved[False]
README.md marge/app.py marge/batch_job.py
README.md marge/app.py marge/batch_job.py