We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Bug: dvc remote remove leads to Initialization error / config file error.
**Setup**

- dvc version 0.18.9, installed with pip, python Anaconda 3.6.4, Ubuntu 16.04

**Repro**

```bash
set -e
set -x
rm -rf foo
mkdir -p foo && cd foo
git init && dvc init
echo bar > bar.txt
dvc remote add -d dummy s3://dummy
dvc remote remove dummy
dvc add bar.txt
```

```bash
+ rm -rf foo
+ mkdir -p foo
+ cd foo
+ git init
Initialized empty Git repository in /home/tmain/foo/.git/
+ dvc init
Adding '.dvc/state' to '.dvc/.gitignore'.
Adding '.dvc/state.lock' to '.dvc/.gitignore'.
Adding '.dvc/link.state' to '.dvc/.gitignore'.
Adding '.dvc/link.state.lock' to '.dvc/.gitignore'.
Adding '.dvc/lock' to '.dvc/.gitignore'.
Adding '.dvc/config.local' to '.dvc/.gitignore'.
Adding '.dvc/updater' to '.dvc/.gitignore'.
Adding '.dvc/cache' to '.dvc/.gitignore'.
Checking for updates...
+ echo bar
+ dvc remote add -d dummy s3://dummy
Setting 'dummy' as a default remote.
+ dvc remote remove dummy
+ dvc add bar.txt
Error: Initialization error: Config file error: Can't find remote section 'remote "dummy"' in config

```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `dvc/command/remote.py`
Content:
```
1 import re
2 
3 from dvc.config import Config
4 from dvc.command.config import CmdConfig
5 from dvc.logger import Logger
6 
7 
8 class CmdRemoteAdd(CmdConfig):
9     def run(self):
10         section = Config.SECTION_REMOTE_FMT.format(self.args.name)
11         ret = self.set(section, Config.SECTION_REMOTE_URL, self.args.url)
12         if ret != 0:
13             return ret
14 
15         if self.args.default:
16             msg = 'Setting \'{}\' as a default remote.'.format(self.args.name)
17             Logger.info(msg)
18             ret = self.set(Config.SECTION_CORE,
19                            Config.SECTION_CORE_REMOTE,
20                            self.args.name)
21 
22         return ret
23 
24 
25 class CmdRemoteRemove(CmdConfig):
26     def run(self):
27         section = Config.SECTION_REMOTE_FMT.format(self.args.name)
28         return self.unset(section, Config.SECTION_REMOTE_URL)
29 
30 
31 class CmdRemoteModify(CmdConfig):
32     def run(self):
33         section = Config.SECTION_REMOTE_FMT.format(self.args.name)
34         self.args.name = '{}.{}'.format(section, self.args.option)
35         return super(CmdRemoteModify, self).run()
36 
37 
38 class CmdRemoteList(CmdConfig):
39     def run(self):
40         for section in self.configobj.keys():
41             r = re.match(Config.SECTION_REMOTE_REGEX, section)
42             if r:
43                 name = r.group('name')
44                 url = self.configobj[section].get(Config.SECTION_REMOTE_URL,
45                                                   '')
46                 Logger.info('{}\t{}'.format(name, url))
47         return 0
48
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/dvc/command/remote.py b/dvc/command/remote.py
--- a/dvc/command/remote.py
+++ b/dvc/command/remote.py
@@ -1,4 +1,6 @@
+import os
 import re
+import configobj
 
 from dvc.config import Config
 from dvc.command.config import CmdConfig
@@ -23,9 +25,35 @@
 
 
 class CmdRemoteRemove(CmdConfig):
+    def _remove_default(self, config_file, remote):
+        path = os.path.join(os.path.dirname(self.config_file),
+                            config_file)
+        config = configobj.ConfigObj(path)
+
+        core = config.get(Config.SECTION_CORE, None)
+        if core is None:
+            return
+
+        default = core.get(Config.SECTION_CORE_REMOTE, None)
+        if default is None:
+            return
+
+        if default == remote:
+            del config[Config.SECTION_CORE][Config.SECTION_CORE_REMOTE]
+            if len(config[Config.SECTION_CORE]) == 0:
+                del config[Config.SECTION_CORE]
+
+        config.write()
+
     def run(self):
         section = Config.SECTION_REMOTE_FMT.format(self.args.name)
-        return self.unset(section, Config.SECTION_REMOTE_URL)
+        ret = self.unset(section)
+        if ret != 0:
+            return ret
+
+        self._remove_default(Config.CONFIG, self.args.name)
+        self._remove_default(Config.CONFIG_LOCAL, self.args.name)
+        return 0
 
 
 class CmdRemoteModify(CmdConfig):

{"golden_diff": "diff --git a/dvc/command/remote.py b/dvc/command/remote.py\n--- a/dvc/command/remote.py\n+++ b/dvc/command/remote.py\n@@ -1,4 +1,6 @@\n+import os\n import re\n+import configobj\n \n from dvc.config import Config\n from dvc.command.config import CmdConfig\n@@ -23,9 +25,35 @@\n \n \n class CmdRemoteRemove(CmdConfig):\n+    def _remove_default(self, config_file, remote):\n+        path = os.path.join(os.path.dirname(self.config_file),\n+                            config_file)\n+        config = configobj.ConfigObj(path)\n+\n+        core = config.get(Config.SECTION_CORE, None)\n+        if core is None:\n+            return\n+\n+        default = core.get(Config.SECTION_CORE_REMOTE, None)\n+        if default is None:\n+            return\n+\n+        if default == remote:\n+            del config[Config.SECTION_CORE][Config.SECTION_CORE_REMOTE]\n+            if len(config[Config.SECTION_CORE]) == 0:\n+                del config[Config.SECTION_CORE]\n+\n+        config.write()\n+\n     def run(self):\n         section = Config.SECTION_REMOTE_FMT.format(self.args.name)\n-        return self.unset(section, Config.SECTION_REMOTE_URL)\n+        ret = self.unset(section)\n+        if ret != 0:\n+            return ret\n+\n+        self._remove_default(Config.CONFIG, self.args.name)\n+        self._remove_default(Config.CONFIG_LOCAL, self.args.name)\n+        return 0\n \n \n class CmdRemoteModify(CmdConfig):\n", "issue": "Bug: dvc remote remove leads to Initialization error / config file error.\n**Setup**\r\n\r\n- dvc version 0.18.9, installed with pip, python Anaconda 3.6.4, Ubuntu 16.04\r\n\r\n**Repro**\r\n\r\n```bash\r\nset -e\r\nset -x\r\nrm -rf foo\r\nmkdir -p foo && cd foo\r\ngit init && dvc init\r\necho bar > bar.txt\r\ndvc remote add -d dummy s3://dummy\r\ndvc remote remove dummy\r\ndvc add bar.txt\r\n```\r\n\r\n```bash\r\n+ rm -rf foo\r\n+ mkdir -p foo\r\n+ cd foo\r\n+ git init\r\nInitialized empty Git repository in /home/tmain/foo/.git/\r\n+ dvc init\r\nAdding '.dvc/state' to '.dvc/.gitignore'.\r\nAdding '.dvc/state.lock' to '.dvc/.gitignore'.\r\nAdding '.dvc/link.state' to '.dvc/.gitignore'.\r\nAdding '.dvc/link.state.lock' to '.dvc/.gitignore'.\r\nAdding '.dvc/lock' to '.dvc/.gitignore'.\r\nAdding '.dvc/config.local' to '.dvc/.gitignore'.\r\nAdding '.dvc/updater' to '.dvc/.gitignore'.\r\nAdding '.dvc/cache' to '.dvc/.gitignore'.\r\nChecking for updates...\r\n+ echo bar\r\n+ dvc remote add -d dummy s3://dummy\r\nSetting 'dummy' as a default remote.\r\n+ dvc remote remove dummy\r\n+ dvc add bar.txt\r\nError: Initialization error: Config file error: Can't find remote section 'remote \"dummy\"' in config\r\n\r\n```\n", "before_files": [{"content": "import re\n\nfrom dvc.config import Config\nfrom dvc.command.config import CmdConfig\nfrom dvc.logger import Logger\n\n\nclass CmdRemoteAdd(CmdConfig):\n    def run(self):\n        section = Config.SECTION_REMOTE_FMT.format(self.args.name)\n        ret = self.set(section, Config.SECTION_REMOTE_URL, self.args.url)\n        if ret != 0:\n            return ret\n\n        if self.args.default:\n            msg = 'Setting \\'{}\\' as a default remote.'.format(self.args.name)\n            Logger.info(msg)\n            ret = self.set(Config.SECTION_CORE,\n                           Config.SECTION_CORE_REMOTE,\n                           self.args.name)\n\n        return ret\n\n\nclass CmdRemoteRemove(CmdConfig):\n    def run(self):\n        section = Config.SECTION_REMOTE_FMT.format(self.args.name)\n        return self.unset(section, Config.SECTION_REMOTE_URL)\n\n\nclass CmdRemoteModify(CmdConfig):\n    def run(self):\n        section = Config.SECTION_REMOTE_FMT.format(self.args.name)\n        self.args.name = '{}.{}'.format(section, self.args.option)\n        return super(CmdRemoteModify, self).run()\n\n\nclass CmdRemoteList(CmdConfig):\n    def run(self):\n        for section in self.configobj.keys():\n            r = re.match(Config.SECTION_REMOTE_REGEX, section)\n            if r:\n                name = r.group('name')\n                url = self.configobj[section].get(Config.SECTION_REMOTE_URL,\n                                                  '')\n                Logger.info('{}\\t{}'.format(name, url))\n        return 0\n", "path": "dvc/command/remote.py"}], "after_files": [{"content": "import os\nimport re\nimport configobj\n\nfrom dvc.config import Config\nfrom dvc.command.config import CmdConfig\nfrom dvc.logger import Logger\n\n\nclass CmdRemoteAdd(CmdConfig):\n    def run(self):\n        section = Config.SECTION_REMOTE_FMT.format(self.args.name)\n        ret = self.set(section, Config.SECTION_REMOTE_URL, self.args.url)\n        if ret != 0:\n            return ret\n\n        if self.args.default:\n            msg = 'Setting \\'{}\\' as a default remote.'.format(self.args.name)\n            Logger.info(msg)\n            ret = self.set(Config.SECTION_CORE,\n                           Config.SECTION_CORE_REMOTE,\n                           self.args.name)\n\n        return ret\n\n\nclass CmdRemoteRemove(CmdConfig):\n    def _remove_default(self, config_file, remote):\n        path = os.path.join(os.path.dirname(self.config_file),\n                            config_file)\n        config = configobj.ConfigObj(path)\n\n        core = config.get(Config.SECTION_CORE, None)\n        if core is None:\n            return\n\n        default = core.get(Config.SECTION_CORE_REMOTE, None)\n        if default is None:\n            return\n\n        if default == remote:\n            del config[Config.SECTION_CORE][Config.SECTION_CORE_REMOTE]\n            if len(config[Config.SECTION_CORE]) == 0:\n                del config[Config.SECTION_CORE]\n\n        config.write()\n\n    def run(self):\n        section = Config.SECTION_REMOTE_FMT.format(self.args.name)\n        ret = self.unset(section)\n        if ret != 0:\n            return ret\n\n        self._remove_default(Config.CONFIG, self.args.name)\n        self._remove_default(Config.CONFIG_LOCAL, self.args.name)\n        return 0\n\n\nclass CmdRemoteModify(CmdConfig):\n    def run(self):\n        section = Config.SECTION_REMOTE_FMT.format(self.args.name)\n        self.args.name = '{}.{}'.format(section, self.args.option)\n        return super(CmdRemoteModify, self).run()\n\n\nclass CmdRemoteList(CmdConfig):\n    def run(self):\n        for section in self.configobj.keys():\n            r = re.match(Config.SECTION_REMOTE_REGEX, section)\n            if r:\n                name = r.group('name')\n                url = self.configobj[section].get(Config.SECTION_REMOTE_URL,\n                                                  '')\n                Logger.info('{}\\t{}'.format(name, url))\n        return 0\n", "path": "dvc/command/remote.py"}]}