|
@@ -11,6 +11,7 @@ import os
|
|
import sys
|
|
import sys
|
|
import tempfile
|
|
import tempfile
|
|
import threading
|
|
import threading
|
|
|
|
+from collections import defaultdict
|
|
import unittest
|
|
import unittest
|
|
from unittest import mock
|
|
from unittest import mock
|
|
|
|
|
|
@@ -449,28 +450,82 @@ class GitConfigStateTestTest(unittest.TestCase):
|
|
self.assertDictEqual(m.load_config(), {})
|
|
self.assertDictEqual(m.load_config(), {})
|
|
|
|
|
|
gs['section.key'] = ['override']
|
|
gs['section.key'] = ['override']
|
|
- self.assertDictEqual(m.load_config(), {'section.key': ['override']})
|
|
|
|
|
|
+ self.assertDictEqual(
|
|
|
|
+ m.load_config(), {
|
|
|
|
+ "global": {
|
|
|
|
+ 'section.key': ['override']
|
|
|
|
+ },
|
|
|
|
+ "default": {
|
|
|
|
+ 'section.key': ['override']
|
|
|
|
+ },
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ def defaultdict_to_dict(self, d):
|
|
|
|
+ if isinstance(d, defaultdict):
|
|
|
|
+ return {k: self.defaultdict_to_dict(v) for k, v in d.items()}
|
|
|
|
+ return d
|
|
|
|
|
|
def test_construction_global(self):
|
|
def test_construction_global(self):
|
|
- m, gs = self._make(global_state={'section.key': ['global']})
|
|
|
|
- self.assertDictEqual(gs, {'section.key': ['global']})
|
|
|
|
- self.assertDictEqual(m.load_config(), {'section.key': ['global']})
|
|
|
|
|
|
+
|
|
|
|
+ m, gs = self._make(global_state={
|
|
|
|
+ 'section.key': ['global'],
|
|
|
|
+ })
|
|
|
|
+ self.assertDictEqual(self.defaultdict_to_dict(gs),
|
|
|
|
+ {'section.key': ['global']})
|
|
|
|
+ self.assertDictEqual(
|
|
|
|
+ self.defaultdict_to_dict(m.load_config()), {
|
|
|
|
+ "global": {
|
|
|
|
+ 'section.key': ['global']
|
|
|
|
+ },
|
|
|
|
+ "default": {
|
|
|
|
+ 'section.key': ['global']
|
|
|
|
+ },
|
|
|
|
+ })
|
|
|
|
|
|
gs['section.key'] = ['override']
|
|
gs['section.key'] = ['override']
|
|
- self.assertDictEqual(m.load_config(), {'section.key': ['override']})
|
|
|
|
|
|
+ self.assertDictEqual(
|
|
|
|
+ self.defaultdict_to_dict(m.load_config()), {
|
|
|
|
+ "global": {
|
|
|
|
+ 'section.key': ['override']
|
|
|
|
+ },
|
|
|
|
+ "default": {
|
|
|
|
+ 'section.key': ['override']
|
|
|
|
+ },
|
|
|
|
+ })
|
|
|
|
|
|
def test_construction_system(self):
|
|
def test_construction_system(self):
|
|
m, gs = self._make(
|
|
m, gs = self._make(
|
|
global_state={'section.key': ['global']},
|
|
global_state={'section.key': ['global']},
|
|
system_state={'section.key': ['system']},
|
|
system_state={'section.key': ['system']},
|
|
)
|
|
)
|
|
- self.assertDictEqual(gs, {'section.key': ['global']})
|
|
|
|
- self.assertDictEqual(m.load_config(),
|
|
|
|
- {'section.key': ['system', 'global']})
|
|
|
|
|
|
+ self.assertDictEqual(self.defaultdict_to_dict(gs),
|
|
|
|
+ {'section.key': ['global']})
|
|
|
|
+ self.assertDictEqual(
|
|
|
|
+ self.defaultdict_to_dict(m.load_config()), {
|
|
|
|
+ 'default': {
|
|
|
|
+ 'section.key': ['system', 'global']
|
|
|
|
+ },
|
|
|
|
+ "global": {
|
|
|
|
+ 'section.key': ['global']
|
|
|
|
+ },
|
|
|
|
+ "system": {
|
|
|
|
+ 'section.key': ['system']
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
|
|
gs['section.key'] = ['override']
|
|
gs['section.key'] = ['override']
|
|
- self.assertDictEqual(m.load_config(),
|
|
|
|
- {'section.key': ['system', 'override']})
|
|
|
|
|
|
+ self.assertDictEqual(
|
|
|
|
+ self.defaultdict_to_dict(m.load_config()), {
|
|
|
|
+ "global": {
|
|
|
|
+ 'section.key': ['override']
|
|
|
|
+ },
|
|
|
|
+ "system": {
|
|
|
|
+ 'section.key': ['system']
|
|
|
|
+ },
|
|
|
|
+ 'default': {
|
|
|
|
+ 'section.key': ['system', 'override']
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
|
|
def test_set_config_system(self):
|
|
def test_set_config_system(self):
|
|
m, _ = self._make()
|
|
m, _ = self._make()
|
|
@@ -496,9 +551,15 @@ class GitConfigStateTestTest(unittest.TestCase):
|
|
self.assertDictEqual(m.load_config(), {})
|
|
self.assertDictEqual(m.load_config(), {})
|
|
|
|
|
|
m.set_config('section.key', 'new_global', append=True, scope='global')
|
|
m.set_config('section.key', 'new_global', append=True, scope='global')
|
|
- self.assertDictEqual(m.load_config(), {
|
|
|
|
- 'section.key': ['new_global'],
|
|
|
|
- })
|
|
|
|
|
|
+ self.assertDictEqual(
|
|
|
|
+ m.load_config(), {
|
|
|
|
+ "default": {
|
|
|
|
+ 'section.key': ['new_global']
|
|
|
|
+ },
|
|
|
|
+ "global": {
|
|
|
|
+ 'section.key': ['new_global']
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
|
|
def test_set_config_global(self):
|
|
def test_set_config_global(self):
|
|
m, gs = self._make()
|
|
m, gs = self._make()
|
|
@@ -506,44 +567,64 @@ class GitConfigStateTestTest(unittest.TestCase):
|
|
self.assertDictEqual(m.load_config(), {})
|
|
self.assertDictEqual(m.load_config(), {})
|
|
|
|
|
|
m.set_config('section.key', 'new_global', append=False, scope='global')
|
|
m.set_config('section.key', 'new_global', append=False, scope='global')
|
|
- self.assertDictEqual(m.load_config(), {
|
|
|
|
- 'section.key': ['new_global'],
|
|
|
|
- })
|
|
|
|
|
|
+ self.assertDictEqual(
|
|
|
|
+ self.defaultdict_to_dict(m.load_config()), {
|
|
|
|
+ "global": {
|
|
|
|
+ 'section.key': ['new_global']
|
|
|
|
+ },
|
|
|
|
+ "default": {
|
|
|
|
+ 'section.key': ['new_global']
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
|
|
m.set_config('section.key', 'new_global2', append=True, scope='global')
|
|
m.set_config('section.key', 'new_global2', append=True, scope='global')
|
|
- self.assertDictEqual(m.load_config(), {
|
|
|
|
- 'section.key': ['new_global', 'new_global2'],
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- self.assertDictEqual(gs, {
|
|
|
|
- 'section.key': ['new_global', 'new_global2'],
|
|
|
|
- })
|
|
|
|
|
|
+ self.assertDictEqual(
|
|
|
|
+ self.defaultdict_to_dict(m.load_config()), {
|
|
|
|
+ "global": {
|
|
|
|
+ 'section.key': ['new_global', 'new_global2']
|
|
|
|
+ },
|
|
|
|
+ "default": {
|
|
|
|
+ 'section.key': ['new_global', 'new_global2']
|
|
|
|
+ },
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ self.assertDictEqual(self.defaultdict_to_dict(gs),
|
|
|
|
+ {'section.key': ['new_global', 'new_global2']})
|
|
|
|
|
|
def test_set_config_multi_global(self):
|
|
def test_set_config_multi_global(self):
|
|
- m, gs = self._make(global_state={
|
|
|
|
- 'section.key': ['1', '2'],
|
|
|
|
- })
|
|
|
|
|
|
+ m, gs = self._make(global_state={'section.key': ['1', '2']})
|
|
|
|
|
|
m.set_config_multi('section.key',
|
|
m.set_config_multi('section.key',
|
|
'new_global',
|
|
'new_global',
|
|
value_pattern=None,
|
|
value_pattern=None,
|
|
scope='global')
|
|
scope='global')
|
|
- self.assertDictEqual(m.load_config(), {
|
|
|
|
- 'section.key': ['new_global'],
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- self.assertDictEqual(gs, {
|
|
|
|
- 'section.key': ['new_global'],
|
|
|
|
- })
|
|
|
|
|
|
+ self.assertDictEqual(
|
|
|
|
+ self.defaultdict_to_dict(m.load_config()), {
|
|
|
|
+ "default": {
|
|
|
|
+ 'section.key': ['new_global']
|
|
|
|
+ },
|
|
|
|
+ "global": {
|
|
|
|
+ 'section.key': ['new_global']
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ self.assertDictEqual(gs, {'section.key': ['new_global']})
|
|
|
|
|
|
m.set_config_multi('othersection.key',
|
|
m.set_config_multi('othersection.key',
|
|
'newval',
|
|
'newval',
|
|
value_pattern=None,
|
|
value_pattern=None,
|
|
scope='global')
|
|
scope='global')
|
|
- self.assertDictEqual(m.load_config(), {
|
|
|
|
- 'section.key': ['new_global'],
|
|
|
|
- 'othersection.key': ['newval'],
|
|
|
|
- })
|
|
|
|
|
|
+ self.assertDictEqual(
|
|
|
|
+ m.load_config(), {
|
|
|
|
+ "global": {
|
|
|
|
+ 'section.key': ['new_global'],
|
|
|
|
+ 'othersection.key': ['newval'],
|
|
|
|
+ },
|
|
|
|
+ "default": {
|
|
|
|
+ 'section.key': ['new_global'],
|
|
|
|
+ 'othersection.key': ['newval'],
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
|
|
self.assertDictEqual(gs, {
|
|
self.assertDictEqual(gs, {
|
|
'section.key': ['new_global'],
|
|
'section.key': ['new_global'],
|
|
@@ -559,17 +640,29 @@ class GitConfigStateTestTest(unittest.TestCase):
|
|
'new_global',
|
|
'new_global',
|
|
value_pattern='2',
|
|
value_pattern='2',
|
|
scope='global')
|
|
scope='global')
|
|
- self.assertDictEqual(m.load_config(), {
|
|
|
|
- 'section.key': ['1', '1', 'new_global', '3'],
|
|
|
|
- })
|
|
|
|
|
|
+ self.assertDictEqual(
|
|
|
|
+ m.load_config(), {
|
|
|
|
+ "global": {
|
|
|
|
+ 'section.key': ['1', '1', 'new_global', '3']
|
|
|
|
+ },
|
|
|
|
+ "default": {
|
|
|
|
+ 'section.key': ['1', '1', 'new_global', '3']
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
|
|
m.set_config_multi('section.key',
|
|
m.set_config_multi('section.key',
|
|
'additional',
|
|
'additional',
|
|
value_pattern='narp',
|
|
value_pattern='narp',
|
|
scope='global')
|
|
scope='global')
|
|
- self.assertDictEqual(m.load_config(), {
|
|
|
|
- 'section.key': ['1', '1', 'new_global', '3', 'additional'],
|
|
|
|
- })
|
|
|
|
|
|
+ self.assertDictEqual(
|
|
|
|
+ m.load_config(), {
|
|
|
|
+ "default": {
|
|
|
|
+ 'section.key': ['1', '1', 'new_global', '3', 'additional']
|
|
|
|
+ },
|
|
|
|
+ "global": {
|
|
|
|
+ 'section.key': ['1', '1', 'new_global', '3', 'additional']
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
|
|
def test_unset_config_global(self):
|
|
def test_unset_config_global(self):
|
|
m, _ = self._make(global_state={
|
|
m, _ = self._make(global_state={
|
|
@@ -595,19 +688,34 @@ class GitConfigStateTestTest(unittest.TestCase):
|
|
|
|
|
|
m.unset_config('section.key', scope='global', missing_ok=False)
|
|
m.unset_config('section.key', scope='global', missing_ok=False)
|
|
self.assertDictEqual(m.load_config(), {
|
|
self.assertDictEqual(m.load_config(), {
|
|
- 'extra': ['another'],
|
|
|
|
|
|
+ "global": {
|
|
|
|
+ 'extra': ['another']
|
|
|
|
+ },
|
|
|
|
+ "default": {
|
|
|
|
+ 'extra': ['another']
|
|
|
|
+ }
|
|
})
|
|
})
|
|
|
|
|
|
with self.assertRaises(scm.GitConfigUnsetMissingValue):
|
|
with self.assertRaises(scm.GitConfigUnsetMissingValue):
|
|
m.unset_config('section.key', scope='global', missing_ok=False)
|
|
m.unset_config('section.key', scope='global', missing_ok=False)
|
|
|
|
|
|
self.assertDictEqual(m.load_config(), {
|
|
self.assertDictEqual(m.load_config(), {
|
|
- 'extra': ['another'],
|
|
|
|
|
|
+ "global": {
|
|
|
|
+ 'extra': ['another']
|
|
|
|
+ },
|
|
|
|
+ "default": {
|
|
|
|
+ 'extra': ['another']
|
|
|
|
+ }
|
|
})
|
|
})
|
|
|
|
|
|
m.unset_config('section.key', scope='global', missing_ok=True)
|
|
m.unset_config('section.key', scope='global', missing_ok=True)
|
|
self.assertDictEqual(m.load_config(), {
|
|
self.assertDictEqual(m.load_config(), {
|
|
- 'extra': ['another'],
|
|
|
|
|
|
+ "global": {
|
|
|
|
+ 'extra': ['another']
|
|
|
|
+ },
|
|
|
|
+ "default": {
|
|
|
|
+ 'extra': ['another']
|
|
|
|
+ }
|
|
})
|
|
})
|
|
|
|
|
|
def test_unset_config_global_multi(self):
|
|
def test_unset_config_global_multi(self):
|
|
@@ -644,9 +752,15 @@ class GitConfigStateTestTest(unittest.TestCase):
|
|
value_pattern='2',
|
|
value_pattern='2',
|
|
scope='global',
|
|
scope='global',
|
|
missing_ok=False)
|
|
missing_ok=False)
|
|
- self.assertDictEqual(m.load_config(), {
|
|
|
|
- 'section.key': ['1', '3', '1'],
|
|
|
|
- })
|
|
|
|
|
|
+ self.assertDictEqual(
|
|
|
|
+ m.load_config(), {
|
|
|
|
+ 'global': {
|
|
|
|
+ 'section.key': ['1', '3', '1'],
|
|
|
|
+ },
|
|
|
|
+ 'default': {
|
|
|
|
+ 'section.key': ['1', '3', '1'],
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
|
|
|
|
|
|
class CanonicalizeGitConfigKeyTest(unittest.TestCase):
|
|
class CanonicalizeGitConfigKeyTest(unittest.TestCase):
|