From b58b3b8bee3725a940becc31a29d6cd59d4e76f5 Mon Sep 17 00:00:00 2001
From: Daniel Vetter <daniel.vetter@ffwll.ch>
Date: Wed, 16 Nov 2016 17:38:26 +0100
Subject: [PATCH] dim: autodetect branches in rebuild-nightly

Needs new url-mapping information in nightly.conf to work properly. Only
leftover bit from my original patch after rebasing is to abstract away
the remote for the integration tree.

v2:
- Fix typo when calling rr_cache_dir. Oops.
- Use cut -f 1 instead of sed/regex horrors (jani).

v3: Fix bug that resulted in nesting rr-cache directories.

v4: Rebasing.

v5: Resurrect $repo (as $remote) printing when fetching branches,
originally from my patch.

v6: Use remote instead of origin local variables, to be more
consistent. Picked up from Jani.

v7: Move misplaced hunks to right place.

v8: For the nightly remote use nightly_remote instead of anything
called origin - it's confusing.

v9: Create a separate rerere_remote for the rerere-cache branch. It
might be in a difference local git repository (Jani).

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
---
 dim | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/dim b/dim
index 80ca562..e765d67 100755
--- a/dim
+++ b/dim
@@ -223,6 +223,14 @@ function url_to_remote # url
 	echo $remote
 }
 
+function branch_to_remote # branch
+{
+	local remote=`git rev-parse --abbrev-ref --symbolic-full-name $1@{upstream}`
+	remote=${remote%%/*}
+
+	echo $remote
+}
+
 function dim_uptodate
 {
 	local using="${BASH_SOURCE[0]}"
@@ -431,7 +439,9 @@ function dim_rebuild_nightly
 
 	echo -n "Updating rerere cache... "
 	cd $rerere
-	if git branch --list rerere-cache | grep '\*' >& /dev/null ; then
+	if git branch --list rerere-cache | grep -q '\*' ; then
+		local rerere_remote=`branch_to_remote rerere-cache`
+
 		git pull >& /dev/null
 		cp `rr_cache_dir`/* rr-cache -r
 		git add *.patch >& /dev/null || true
@@ -442,7 +452,7 @@ function dim_rebuild_nightly
 			echo -n "Nothing changed. "
 		fi
 		echo -n "Pushing rerere cache... "
-		git push $DRY_RUN $nightly_remote HEAD >& /dev/null && echo "Done."
+		git push $DRY_RUN $rerere_remote HEAD >& /dev/null && echo "Done."
 	else
 		echo "Fail: Branch setup for the rerere-cache is borked."
 		exit 1
-- 
GitLab