Skip to content

Commit

Permalink
msubprojects: Handle change of URL in wrap-git
Browse files Browse the repository at this point in the history
  • Loading branch information
xclaesse authored and nirbheek committed Oct 13, 2020
1 parent 47046c3 commit 3ade5bb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
5 changes: 4 additions & 1 deletion docs/markdown/Subprojects.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ To pull latest version of all your subprojects at once, just run the command:
prevent from any loss of local changes.
- If subproject is currently in detached mode, a checkout of the revision from
wrap file is performed. *Since 0.56.0* a rebase is also performed in case the
revision already existed locally by was outdated. If `--reset` is specified,
revision already existed locally but was outdated. If `--reset` is specified,
a hard reset is performed instead of rebase.
- If subproject is currently at the same branch as specified by the wrap file,
a rebase on `origin` commit is performed. *Since 0.56.0* If `--reset` is
Expand All @@ -312,6 +312,9 @@ To pull latest version of all your subprojects at once, just run the command:
file is performed and a rebase is also performed in case the revision already
existed locally by was outdated. If `--reset` is specified, a hard reset is
performed instead of rebase.
- *Since 0.56.0* if the `url` specified in wrap file is different to the URL set
on `origin` for a git repository it will not be updated, unless `--reset` is
specified in which case the URL of `origin` will be reset first.

### Start a topic branch across all git subprojects

Expand Down
5 changes: 4 additions & 1 deletion docs/markdown/snippets/subprojects_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ If the command fails on any subproject the execution continues with other
subprojects, but at the end an error code is now returned.

The `update` subcommand has been reworked:
- In the case the URL of `origin` is different as the `url` set in wrap file,
the subproject will not be updated unless `--reset` is specified (see below).
- The `--rebase` behaviour is now the default for consistency: it was
already rebasing when current branch and revision are the same, it is
less confusing to rebase when they are different too.
- Add `--reset` mode that checkout the new branch and hard reset that
branch to remote commit. This new mode guarantees that every
subproject are exactly at the wrap's revision.
subproject are exactly at the wrap's revision. In addition the URL of `origin`
is updated in case it changed in the wrap file.
- Local changes are always stashed first to avoid any data loss. In the
worst case scenario the user can always check reflog and stash list to
rollback.
28 changes: 25 additions & 3 deletions mesonbuild/msubprojects.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,33 @@ def update_git(wrap, repo_dir, options):
if not os.path.isdir(repo_dir):
mlog.log(' -> Not used.')
return True
revision = wrap.get('revision')
if not revision:
revision = wrap.values.get('revision')
url = wrap.values.get('url')
push_url = wrap.values.get('push-url')
if not revision or not url:
# It could be a detached git submodule for example.
mlog.log(' -> No revision specified.')
mlog.log(' -> No revision or URL specified.')
return True
try:
origin_url = git_output(['remote', 'get-url', 'origin'], repo_dir).strip()
except GitException as e:
mlog.log(' -> Failed to determine current origin URL in', mlog.bold(repo_dir))
mlog.log(mlog.red(e.output))
mlog.log(mlog.red(str(e)))
return False
if options.reset:
try:
git_output(['remote', 'set-url', 'origin', url], repo_dir)
if push_url:
git_output(['remote', 'set-url', '--push', 'origin', push_url], repo_dir)
except GitException as e:
mlog.log(' -> Failed to reset origin URL in', mlog.bold(repo_dir))
mlog.log(mlog.red(e.output))
mlog.log(mlog.red(str(e)))
return False
elif url != origin_url:
mlog.log(' -> URL changed from {!r} to {!r}'.format(origin_url, url))
return False
try:
# Same as `git branch --show-current` but compatible with older git version
branch = git_output(['rev-parse', '--abbrev-ref', 'HEAD'], repo_dir).strip()
Expand Down

0 comments on commit 3ade5bb

Please sign in to comment.