2024-11-03 12:11 AM - edited 2024-11-03 12:22 AM
I had an issue, that i could not reproduce, because i could not restore the exact state of the project. The CubeIDE has its own version control for each file, which is of no great use, since the project consists of many files. Because of that i developed my own version control principle:
Everytime a successful build happens, the files are committed to a certain branch of the repo. Then after an issue has been fixed, or i want to try out things / old states of a project, i use smartgit to handle those commits.
Here is how to do it:
1. Create a directory outside of the workspace and manually create backups (backups the git repo too)
2. Setup git in the workspace (learn about git before - its quite a big topic)
3. Create script to commit changesto the specified branch (The parts with "*****" need to be edited)
import os
import time
import datetime
import subprocess
#IDE run command (build steps):
#cmd.exe /k "***** WORKSPACE\...bat"
#cmd.exe /k "..\..\..\gitManager.py"
#../../../gitManager.py ERROR 193 make
gitPath = "*****WORKSPACE"
def signalError():
subprocess.run(f"\"*****/nircmd.exe\" setdefaultsounddevice *****", shell=True)
subprocess.run(f"\"*****nircmd.exe\" beep 1600 800", shell=True)
subprocess.run(f"\"*****/nircmd.exe\" setdefaultsounddevice \"B*****\"", shell=True)
def checkBranch():
gitCmd = f"git -C \"{gitPath}\" branch"
process = subprocess.run(gitCmd, shell=True, capture_output=True, text=True)
if process.returncode == 0:
branches = process.stdout.split('\n')
#print(branches, flush=True)
if not "* Laufende_Entwicklung" in branches:
print("Error wrong branch!", flush=True)
print(f"{process.stdout}", flush=True)
signalError()
return False;
else:
return True;
#print(process.stdout, flush=True)
else:
print("Error while checking for active branch", flush=True)
print(f"{process.stdout}", flush=True)
signalError()
return False;
def gitAddCommit():
gitCmd = f"git -C \"{gitPath}\" add ."
print(f"running: \"{gitCmd}\"", flush=True)
process = subprocess.run(gitCmd, shell=True, capture_output=True, text=True)
if process.returncode == 0:
timeString = f"{datetime.datetime.now():%Y-%m-%d %H:%M}"
gitCmd = f"git -C \"{gitPath}\" commit -m \"{timeString}\""
print(f"running: \"{gitCmd}\"", flush=True)
process = subprocess.run(gitCmd, shell=True, capture_output=True, text=True)
if process.returncode == 0:
print(f"Commit done: {timeString}", flush=True)
return True
else:
print("Error on git commit", flush=True)
print(f"{process.stdout}", flush=True)
signalError()
return False
else:
print("Error on git add", flush=True)
print(f"{process.stdout}", flush=True)
signalError()
return False
print("Git manager running...", flush=True)
if checkBranch():
gitAddCommit()
else:
print("Error nothing committed", flush=True)
#lastTime = thisTime
4. Edit properties to have the script execute after successful build (See picture attached)
Note:
It may have one or more flaws, since it has just beeing developed. Feel free to contribute or givee feedback.