From d62fe7b0b93977dfcff5b62a52a56721ebd6a58a Mon Sep 17 00:00:00 2001
From: Francois Andrieu <naolwen@gmail.com>
Date: Jul 27 2020 20:29:21 +0000
Subject: [PATCH 1/5] openshift based dockerfile


---

diff --git a/Dockerfile b/Dockerfile
index 8ea16ea..e9c0418 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,12 +1,11 @@
-# asamalik/fedora-docs-translations
-
-FROM fedora:29
-
-RUN dnf -y install po4a vim git findutils tree
-
-# Workaround: I need a patch for po4a that hasn't been released, yet.
-
-RUN mkdir -p /usr/share/custom-po4a && \
-    git clone https://github.com/mquinson/po4a.git /usr/share/custom-po4a
-
-ENV PERLLIB /usr/share/custom-po4a/lib
+FROM fedora:32
+RUN dnf -y install \
+        po4a \
+        git \
+        findutils \
+        python3-pyyaml \
+        "perl(YAML::Tiny)"
+ENV HOME /workspace
+COPY . /workspace
+RUN chmod -R g+w /workspace
+WORKDIR /workspace

From 423ab19ccbbd542281ff696215653e5f30d99538 Mon Sep 17 00:00:00 2001
From: Francois Andrieu <naolwen@gmail.com>
Date: Jul 28 2020 16:45:25 +0000
Subject: [PATCH 2/5] unstage pot file if no relevant changes detected


---

diff --git a/.githooks/pre-commit b/.githooks/pre-commit
index 687486e..fdf1621 100755
--- a/.githooks/pre-commit
+++ b/.githooks/pre-commit
@@ -13,7 +13,7 @@ function clean_tmp() {
 
 trap clean_tmp exit
 
-for staged in $(git status --porcelain); do
+for staged in $(git diff --name-only --cached); do
     if [ "${staged##*.}" == "pot" ] ; then
         echo "$staged"
         git diff --no-ext-diff --cached --patch-with-raw --output="$output" "$staged"
@@ -25,7 +25,12 @@ for staged in $(git status --porcelain); do
 
         if [ "$countChanges" -eq $(("$countDateAdd" + "$countDateRem")) ] ; then
             echo "the file $staged only contains POT-Creation-Date"
-            git rm --cached "$staged"
+            git reset HEAD "$staged"
         fi
     fi
 done
+
+if [ $(git diff --name-only --cached | wc -l) -eq 0 ]; then
+	echo "nothing to commit, aborting..."
+	exit 1
+fi

From 106d1bdff442d8b3ec187c90c9c7b1998c384bfc Mon Sep 17 00:00:00 2001
From: Francois Andrieu <naolwen@gmail.com>
Date: Jul 28 2020 16:45:25 +0000
Subject: [PATCH 3/5] quiet mode for git reset


---

diff --git a/.githooks/pre-commit b/.githooks/pre-commit
index fdf1621..7ab3e5a 100755
--- a/.githooks/pre-commit
+++ b/.githooks/pre-commit
@@ -25,7 +25,7 @@ for staged in $(git diff --name-only --cached); do
 
         if [ "$countChanges" -eq $(("$countDateAdd" + "$countDateRem")) ] ; then
             echo "the file $staged only contains POT-Creation-Date"
-            git reset HEAD "$staged"
+            git reset -q HEAD "$staged"
         fi
     fi
 done

From 4085a4022a836092c0105fd8d267bd63305f2b24 Mon Sep 17 00:00:00 2001
From: Francois Andrieu <naolwen@gmail.com>
Date: Jul 28 2020 16:46:26 +0000
Subject: [PATCH 4/5] We don't need to do this anymore since we're moving to openshift


Revert "hop"

This reverts commit 0d561a4088fed543d69549ac76396d8869e8a26c.

---

diff --git a/build.py b/build.py
index 1857d52..c34e3b6 100755
--- a/build.py
+++ b/build.py
@@ -123,7 +123,6 @@ def clone_l10n(repo_name):
     repo_dir = os.path.dirname(os.path.abspath(__file__)) + "/l10n/" + repo_name
 
     if os.path.exists(repo_dir):
-        subprocess.run(['git', 'reset', "--hard", "origin"], check=True, cwd=repo_dir)
         subprocess.run(['git', 'pull', "--quiet"], check=True, cwd=repo_dir)
     else:
         subprocess.run(["git", "clone", url, repo_dir, "--config",
@@ -139,7 +138,6 @@ def clone_translated_source():
     url = "https://pagure.io/fedora-docs/translated-sources.git"
 
     if os.path.exists(repo_dir):
-        subprocess.run(['git', 'reset', "--hard", "origin"], check=True, cwd=repo_dir)
         subprocess.run(['git', 'pull', "--quiet"], check=True, cwd=repo_dir)
     else:
         subprocess.run(["git", "clone", url, repo_dir, "--config",
@@ -189,7 +187,7 @@ def commit_l10n(repo_name):
     try:
         # add hooks
         dir_path = os.path.dirname(os.path.abspath(__file__))
-        shutil.copytree(os.path.join(dir_path, '.githooks'), os.path.join(repo_dir, '.githooks'))
+        shutil.copytree(os.path.join(dir_path, '.githooks'), os.path.join(repo_dir, '.githooks'), dirs_exist_ok=True)
 
         shutil.copy(os.path.join(dir_path, 'check.sh'), os.path.join(repo_dir, 'check.sh'))
         subprocess.run(['./check.sh'], check=True, cwd=repo_dir)
@@ -207,7 +205,7 @@ def commit_l10n(repo_name):
         else:
             print(" No changes to commit", flush=True)
     except subprocess.CalledProcessError as e:
-        print("** ERROR " + (e.output if e.output else str(e.returncode)))
+        print("** ERROR" + e.output)
 
 def clone_sources():
     """List sources repositories from antora yaml file"""

From 2d09dd86fa96a57b5016f32ad0914d1d412ba812 Mon Sep 17 00:00:00 2001
From: Francois Andrieu <naolwen@gmail.com>
Date: Jul 28 2020 19:33:08 +0000
Subject: [PATCH 5/5] only push if commit is successful


---

diff --git a/build.py b/build.py
index c34e3b6..22d7342 100755
--- a/build.py
+++ b/build.py
@@ -158,10 +158,11 @@ def commit_translated_source():
             out = subprocess.run(['git', 'status', lang, '--porcelain'], check=True, cwd=repo_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 
             if out.stdout.decode("utf-8") :
-                subprocess.run(["git", "commit", "-m", "["+lang+"]automatic update of translated content", "--quiet"],
-                                check=True, cwd=repo_dir)
-
-                subprocess.run(['git', 'push', "--quiet"], check=True, cwd=repo_dir)
+                r_commit = subprocess.run(["git", "commit",
+                                          "-m", "["+lang+"]automatic update of translated content", "--quiet"],
+                                          cwd=repo_dir)
+                if r_commit.returncode == 0:
+                    subprocess.run(['git', 'push', "--quiet"], check=True, cwd=repo_dir)
             else:
                 print(" ["+lang+"] No changes to commit", flush=True)
 
@@ -198,10 +199,12 @@ def commit_l10n(repo_name):
         out = subprocess.run(['git', 'status', '--porcelain'], check=True, cwd=repo_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 
         if out.stdout.decode("utf-8") :
-            subprocess.run(["git", "commit", "-m", "automatic update of pot/po files", "--quiet"],
-                           check=True, cwd=repo_dir)
+            r_commit = subprocess.run(["git", "commit",
+                                      "-m", "automatic update of pot/po files", "--quiet"],
+                                      cwd=repo_dir)
 
-            subprocess.run(['git', 'push', "--quiet"], check=True, cwd=repo_dir)
+            if r_commit.returncode == 0:
+                subprocess.run(['git', 'push', "--quiet"], check=True, cwd=repo_dir)
         else:
             print(" No changes to commit", flush=True)
     except subprocess.CalledProcessError as e:

