element-hq / element-hq/synapse
The release script crashes if the `master` branch is not tracked locally
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 600
- Avg merge
- 5d 22h
- Merged PRs (30d)
- 51
Description
When attempting to use the `merge-back` command in the release script, I discovered that it will fail if one of the expected branches is not present locally. For instance, I did not have a `master` branch locally, and I received the following traceback:
```
➜ ./scripts-dev/release.py merge-back
Merge release-v1.99 → master? [Y/n]:
Switching to release-v1.99 and pulling...
Switching to master and pulling...
Traceback (most recent call last):
File "/home/work/code/synapse/.devenv/state/venv/lib/python3.10/site-packages/git/util.py", line 1125, in __getitem__
return getattr(self, index)
File "/home/work/code/synapse/.devenv/state/venv/lib/python3.10/site-packages/git/util.py", line 1114, in __getattr__
return list.__getattribute__(self, attr)
AttributeError: 'IterableList' object has no attribute 'master'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/work/code/synapse/./scripts-dev/release.py", line 916, in
cli()
File "/home/work/code/synapse/.devenv/state/venv/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
return self.main(*args, **kwargs)
File "/home/work/code/synapse/.devenv/state/venv/lib/python3.10/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
File "/home/work/code/synapse/.devenv/state/venv/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/work/code/synapse/.devenv/state/venv/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/work/code/synapse/.devenv/state/venv/lib/python3.10/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
File "/home/work/code/synapse/./scripts-dev/release.py", line 606, in merge_back
_merge_back()
File "/home/work/code/synapse/./scripts-dev/release.py", line 634, in _merge_back
_merge_into(synapse_repo, branch_name, "master")
File "/home/work/code/synapse/./scripts-dev/release.py", line 507, in _merge_into
repo.heads[branch].checkout()
File "/home/work/code/synapse/.devenv/state/venv/lib/python3.10/site-packages/git/util.py", line 1127, in __getitem__
raise IndexError("No item found with id %r" % (self._prefix + index)) from e
IndexError: No item found with id 'master'
```
To fix it, I had to create a `master` branch, tracking `origin/master`:
```
git checkout origin/master
git checkout master
```
I also ran into a similar problem when attempting to merge `release-v1.99` -> `master` on SyTest:
SyTest traceback
```
On SyTest, merge release-v1.99 → master? [Y/n]:
Switching to release-v1.99 and pulling...
Traceback (most recent call last):
File "/home/work/code/synapse/.devenv/state/venv/lib/python3.10/site-packages/git/util.py", line 1125, in __getitem__
return getattr(self, index)
File "/home/work/code/synapse/.devenv/state/venv/lib/python3.10/site-packages/git/util.py", line 1114, in __getattr__
return list.__getattribute__(self, attr)
AttributeError: 'IterableList' object has no attribute 'release-v1.99'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/work/code/synapse/./scripts-dev/release.py", line 916, in
cli()
File "/home/work/code/synapse/.devenv/state/venv/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
return self.main(*args, **kwargs)
File "/home/work/code/synapse/.devenv/state/venv/lib/python3.10/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
File "/home/work/code/synapse/.devenv/state/venv/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/work/code/synapse/.devenv/state/venv/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/work/code/synapse/.devenv/state/venv/lib/python3.10/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
File "/home/work/code/synapse/./scripts-dev/release.py", line 606, in merge_back
_merge_back()
File "/home/work/code/synapse/./scripts-dev/release.py", line 640, in _merge_back
_merge_into(sytest_repo, branch_name, "master")
File "/home/work/code/synapse/./scripts-dev/release.py", line 507, in _merge_into
repo.heads[branch].checkout()
File "/home/work/code/synapse/.devenv/state/venv/lib/python3.10/site-packages/git/util.py", line 1127, in __getitem__
raise IndexError("No item found with id %r" % (self._prefix + index)) from e
IndexError: No item found with id 'release-v1.99'
```
I can think of two possible solutions:
* Check whether the needed branches exist and if not, error out and tell the user to create them.
* Attempt to create them if `origin/master` and `origin/release-vx.yy` exist. My only concern with this one is it feels a bit too magic for my tastes.
The danger/issue with the current setup is that you may end up in a case where some of the `merge-back` steps end up completed, while others are not. It's easy enough to find out where the script stopped from its output, but once it has stopped, you can't run the `merge-back` command again as it would try to double-merge branches (which is _probably_ fine, but...).
Contributor guide
Research direction
The traceback points to scripts-dev/release.py, especially merge_back/_merge_back and _merge_into around line 507. Reproduce merge-back with a missing local branch, then inspect how both Synapse and SyTest repositories are handled. Done means the command handles absent branches without an unhandled traceback and makes the required next step clear; the intended error-versus-auto-create behavior still needs maintainer agreement.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, python
- Domain
- release, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100