From 9e2780be0522f20bc0f02b00e26159aa24dcb3e5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Loi=CC=88c=20Correnson?= <loic.correnson@cea.fr>
Date: Wed, 12 Feb 2020 17:07:46 +0100
Subject: [PATCH] [Dome] synchronize with external repo

---
 Ivette/.gitignore                     |  1 -
 Ivette/push-dome.sh                   | 31 ---------------
 Ivette/src/dome/.gitignore            |  6 +++
 Ivette/src/dome/template/dome-pull.sh | 50 ++++++++++++++++++++++++
 Ivette/src/dome/template/dome-push.sh | 56 +++++++++++++++++++++++++++
 Ivette/src/dome/template/makefile     | 28 +++++++++++++-
 6 files changed, 138 insertions(+), 34 deletions(-)
 delete mode 100755 Ivette/push-dome.sh
 create mode 100755 Ivette/src/dome/template/dome-pull.sh
 create mode 100755 Ivette/src/dome/template/dome-push.sh

diff --git a/Ivette/.gitignore b/Ivette/.gitignore
index 1efbc2521d6..ba1bdcdb1d9 100644
--- a/Ivette/.gitignore
+++ b/Ivette/.gitignore
@@ -10,6 +10,5 @@ yarn-error.log
 /bin
 /dist
 /html
-/src/dome
 
 # --------------------------------------------------------------------------
diff --git a/Ivette/push-dome.sh b/Ivette/push-dome.sh
deleted file mode 100755
index 4e7e6914e31..00000000000
--- a/Ivette/push-dome.sh
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/bin/sh
-
-DOME=$1
-BRANCH=$2
-
-if [ "$DOME" == "" ] || [ "$BRANCH" == "" ]
-then
-    echo "Usage: push-electron.sh <dome-clone-dir> <new-branch>"
-    exit 1
-fi
-
-git -C $DOME remote -v | grep -q dome/electron.git
-
-if [ "$?" != "0" ]
-then
-    echo "Clone of dome/electron not found in '$DOME'"
-    exit 1
-fi
-
-echo "Push updates to $DOME#$BRANCH"
-
-git -C $DOME checkout -B $BRANCH
-
-FILES=$(cd src/dome ; git ls-files)
-
-for f in $FILES
-do
-    cp -f src/dome/$f $DOME/$f
-done
-
-git -C $DOME commit -a
diff --git a/Ivette/src/dome/.gitignore b/Ivette/src/dome/.gitignore
index 48a7072b2d7..7cd1e3e820f 100644
--- a/Ivette/src/dome/.gitignore
+++ b/Ivette/src/dome/.gitignore
@@ -7,6 +7,12 @@
 .dome-*.orig
 .dome-*.lock
 
+#########################################
+# Dome Repository
+#########################################
+
+/.gitdome
+
 #########################################
 # JavaScript
 #########################################
diff --git a/Ivette/src/dome/template/dome-pull.sh b/Ivette/src/dome/template/dome-pull.sh
new file mode 100755
index 00000000000..b579cf35a1a
--- /dev/null
+++ b/Ivette/src/dome/template/dome-pull.sh
@@ -0,0 +1,50 @@
+# --------------------------------------------------------------------------
+# ---  Pulling Dome Updates
+# --------------------------------------------------------------------------
+
+if [ ! -z "$(git status --porcelain)" ]
+then
+    echo "Local non-commited modifications, aborted."
+    exit 1
+fi
+
+if [ ! -d .gitdome ]
+then
+    git clone git@git.frama-c.com:dome/electron.git .gitdome
+fi
+
+head=$(git rev-parse --abbrev-ref HEAD)
+commit=$(git -C .gitdome rev-parse HEAD)
+remote=$(git -C .gitdome rev-parse --abbrev-ref HEAD)
+
+git checkout stable/dome
+
+if [ "$?" != "0" ]
+then
+    echo "Missing local branch stable/dome, aborted."
+    exit 1
+fi
+
+echo "Pulling Dome updates from $remote to stable/dome..."
+git -C .gitdome pull --prune
+
+for f in $(git -C .gitdome ls-files)
+do
+    mkdir -p $(dirname $f)
+    cp -f .gitdome/$f $f
+    git add $f
+done
+
+if [ ! -z "$(git status --porcelain)" ]
+then
+    git commit -m "[Dome] $commit"
+    echo "Dome repository updated."
+    git checkout $head
+    echo "Merging Dome updates..."
+    git merge stable/dome
+else
+    echo "Dome is already up-to-date."
+    git checkout $head
+fi
+
+# --------------------------------------------------------------------------
diff --git a/Ivette/src/dome/template/dome-push.sh b/Ivette/src/dome/template/dome-push.sh
new file mode 100755
index 00000000000..60816ed9ecb
--- /dev/null
+++ b/Ivette/src/dome/template/dome-push.sh
@@ -0,0 +1,56 @@
+# --------------------------------------------------------------------------
+# ---  Pulling Dome Updates
+# --------------------------------------------------------------------------
+
+branch=$1
+app=$(basename $1)
+
+if [ "$branch" == "" ]
+then
+    echo "Missing branch name, aborted."
+    exit 1
+fi
+
+if [ ! -z "$(git status --porcelain)" ]
+then
+    echo "Local non-commited modifications, aborted."
+    exit 1
+fi
+
+if [ ! -d .gitdome ]
+then
+    git clone git@git.frama-c.com:dome/electron.git .gitdome
+fi
+
+head=$(git rev-parse --abbrev-ref HEAD)
+commit=$(git rev-parse HEAD)
+remote=$(git -C .gitdome rev-parse --abbrev-ref HEAD)
+
+echo "[dome] update $branch"
+git -C .gitdome fetch --prune
+git -C .gitdome checkout $branch
+
+if [ "$?" != "0" ]
+then
+    git -C .gitdome checkout -b $branch
+else
+    git -C .gitdome pull --rebase
+fi
+
+echo "[dome] push updates from $head to $branch..."
+
+for f in $(git ls-files)
+do
+    mkdir -p .gitdome/$(dirname $f)
+    cp -f $f .gitdome/$f
+    git -C .gitdome add $f
+done
+
+echo "[dome] commit $branch"
+git -C .gitdome commit -e -m "[$app] $commit"
+echo "[dome] push $branch"
+git -C .gitdome push origin -f -u $branch
+echo "[dome] back to $remote"
+git -C .gitdome checkout $remote
+
+# --------------------------------------------------------------------------
diff --git a/Ivette/src/dome/template/makefile b/Ivette/src/dome/template/makefile
index 2a555d2ce16..5e5f58e85da 100644
--- a/Ivette/src/dome/template/makefile
+++ b/Ivette/src/dome/template/makefile
@@ -7,13 +7,15 @@
 APP?=$(shell basename $(PWD))
 COPYRIGHT?=CEA Tech
 
+DOME_MK_NAME=$(shell echo $(APP) | tr [:upper:] [:lower:])
+
 DOME?=dome
 DOME_ARGS?=
 DOME_EXPORTS?=
 DOME_PLUGINS?=
 DOME_DOC?=html/dome
-DOME_APP_CLI?=bin/$(shell echo $(APP) | tr [:upper:] [:lower:])
-DOME_APP_DOC?=html/$(shell echo $(APP) | tr [:upper:] [:lower:])
+DOME_APP_CLI?=bin/$(DOME_MK_NAME)
+DOME_APP_DOC?=html/$(DOME_MK_NAME)
 DOME_APP_SRC?=src/renderer
 
 # --------------------------------------------------------------------------
@@ -99,6 +101,28 @@ dome-pkg: .dome-pkg.stamp
 package.json:
 	yarn init
 
+# --------------------------------------------------------------------------
+# ---  Dome Synchronization
+# --------------------------------------------------------------------------
+
+ifneq ("$(DOME)",".")
+
+.PHONY: dome-pull dome-push
+
+dome-pull:
+	@echo "[Dome] ----------------------------------------------------------------"
+	@echo "[Dome] Synchronize with updates"
+	@echo "[Dome] ----------------------------------------------------------------"
+	@(cd $(DOME) && ./template/dome-pull.sh)
+
+dome-push:
+	@echo "[Dome] ----------------------------------------------------------------"
+	@echo "[Dome] Publishing Dome updates to feature/app/$(DOME_MK_NAME)"
+	@echo "[Dome] ----------------------------------------------------------------"
+	@(cd $(DOME) && ./template/dome-push.sh feature/app/$(DOME_MK_NAME))
+
+endif
+
 # --------------------------------------------------------------------------
 # ---  Application Templating
 # --------------------------------------------------------------------------
-- 
GitLab