From 9ab59fc4b7cb7663906ac4471a262434aef57f03 Mon Sep 17 00:00:00 2001 From: Maxime Ripard <mripard@kernel.org> Date: Tue, 27 Feb 2024 12:53:23 +0100 Subject: [PATCH] dim: Handle drm.git move to Gitlab automatically As part of the transition of DRM from cgit to Gitlab, we updated drm-rerere's nightly.conf file to reflect the new URL. However, dim updates drm first and drm-tip lasts, so if you update the git remote URL like we instructed before running dim update-branches (or any command that fetch all remotes), it will error out before it has the chance to retrieve the nightly.conf file. If the user doesn't update the git remote URL, then dim update-branch will run, fetch drm through the cgit repo, update nightly.conf. On the second run, it will detect that the URL doesn't match anymore, but since there's already a drm remote setup, it will fail to add the remote. So, in either case, dim's broken. Add a bit of logic that detects the drm remote URL and will update remote url if we're using our legacy URLs. Co-developed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Maxime Ripard <mripard@kernel.org> --- dim | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/dim b/dim index 1698295..b2ed002 100755 --- a/dim +++ b/dim @@ -130,7 +130,8 @@ dim_extract_tags_marker="# *** extracted tags ***" function read_integration_config { # clear everything first to allow configuration reload - unset drm_tip_repos drm_tip_config + unset drm_tip_repos drm_old_urls drm_tip_config + declare -g -A drm_old_urls declare -g -A drm_tip_repos declare -g -a drm_tip_config @@ -231,30 +232,58 @@ function url_to_repo # url done } -function url_to_remote # url [url ...] +function url_to_remote_from_git # url { local url remote + url="$1" + + remote=$(git remote -v | grep -m 1 "$url/\? (" | cut -f 1) + + echo "$remote" + return 0 +} + +function url_to_remote # url [url ...] +{ + local url remote old_url repo + if [[ "$#" = "0" ]]; then echoerr "url_to_remote without URLs" return 1 fi for url; do - remote=$(git remote -v | grep -m 1 "$url/\? (" | cut -f 1) + remote=$(url_to_remote_from_git "$url") if [[ -n "$remote" ]]; then echo "$remote" return 0 fi done + repo=$(url_to_repo "$url") + for old_url in ${drm_old_urls[$repo]} ; do + remote=$(url_to_remote_from_git "$old_url") + if [[ -n "$remote" ]]; then + if ! ask_user "Update $remote to new $url?"; then + echoerr "Old branch setup found but not updated, aborting" + return 1 + fi + + git remote set-url $remote $url + + echo "$remote" + return 0 + fi + done + echoerr "No git remote for any of the URLs $* found in $(pwd)" url=$1 # default remote to the repo name, but fallback for when bootstrapping # the environment: we may still not have drm-rerere to get the repo # name. In that case, rely on the url - remote=$(url_to_repo "$url") + remote=$repo if [ -z "$remote" ]; then remote=${url%.git} remote=${remote##*/} -- GitLab