Repository: gitpython-developers/GitPython

Issue:
set_tracking_branch fails quietly when .git/config contains an include
I have git-branchless setup in this repository and for the longest time I was confounded, why `set_tracking_branch` did not work (anymore).
Turns out, git-branchless adds an `[include]` section to the `.git/config` file and this causes GitPython to quietly skip writing the config changes back that are necessary for `set_tracking_branch` to have any effect.

Could we maybe set `merge_includes=False` for the config_writer; at least in the Head class?

Discussion:

Patch:
diff --git a/git/repo/base.py b/git/repo/base.py
index 723613c6..ab202654 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -600,7 +600,7 @@ class Repo(object):
             system = system wide configuration file
             global = user level configuration file
             repository = configuration file for this repository only"""
-        return GitConfigParser(self._get_config_path(config_level), read_only=False, repo=self)
+        return GitConfigParser(self._get_config_path(config_level), read_only=False, repo=self, merge_includes=False)
 
     def commit(self, rev: Union[str, Commit_ish, None] = None) -> Commit:
         """The Commit object for the specified revision


Test patch:
diff --git a/test/test_refs.py b/test/test_refs.py
index 5bb83100..4c421767 100644
--- a/test/test_refs.py
+++ b/test/test_refs.py
@@ -15,6 +15,7 @@ from git import (
     SymbolicReference,
     GitCommandError,
     RefLog,
+    GitConfigParser,
 )
 from git.objects.tag import TagObject
 from test.lib import TestBase, with_rw_repo
@@ -172,6 +173,26 @@ class TestRefs(TestBase):
         assert log[0].oldhexsha == pcommit.NULL_HEX_SHA
         assert log[0].newhexsha == pcommit.hexsha
 
+    @with_rw_repo("HEAD", bare=False)
+    def test_set_tracking_branch_with_import(self, rwrepo):
+        # prepare included config file
+        included_config = osp.join(rwrepo.git_dir, "config.include")
+        with GitConfigParser(included_config, read_only=False) as writer:
+            writer.set_value("test", "value", "test")
+        assert osp.exists(included_config)
+
+        with rwrepo.config_writer() as writer:
+            writer.set_value("include", "path", included_config)
+
+        for head in rwrepo.heads:
+            head.set_tracking_branch(None)
+            assert head.tracking_branch() is None
+            remote_ref = rwrepo.remotes[0].refs[0]
+            assert head.set_tracking_branch(remote_ref) is head
+            assert head.tracking_branch() == remote_ref
+            head.set_tracking_branch(None)
+            assert head.tracking_branch() is None
+
     def test_refs(self):
         types_found = set()
         for ref in self.rorepo.refs: