Skip to content

Instantly share code, notes, and snippets.

@wrouesnel
Last active August 29, 2022 09:55
Show Gist options
  • Save wrouesnel/2284c9b523806eab1540 to your computer and use it in GitHub Desktop.
Save wrouesnel/2284c9b523806eab1540 to your computer and use it in GitHub Desktop.
MS Access git merging scripts
# Obviously you're appending these sections.
[core]
ignorecase = true
[merge]
renormalize = true
tool = msaccess-merge
[mergetool "msaccess-merge"]
cmd = $(git rev-parse --show-toplevel)/msaccess-merge "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
trustExitCode = true
' Usage:
' WScript compose.vbs <file> <path>
' Converts all modules, classes, forms and macros in a directory created by "decompose.vbs"
' and composes then into an Access Project file (.adp). This overwrites any existing Modules with the
' same names without warning!!!
' Requires Microsoft Access.
Option Explicit
const acForm = 2
const acModule = 5
const acMacro = 4
const acReport = 3
Const acCmdCompileAndSaveAllModules = &H7E
' BEGIN CODE
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
dim sADPFilename
If (WScript.Arguments.Count = 0) then
MsgBox "Bitte den Dateinamen angeben!", vbExclamation, "Error"
Wscript.Quit()
End if
sADPFilename = fso.GetAbsolutePathName(WScript.Arguments(0))
Dim sPath
If (WScript.Arguments.Count = 1) then
sPath = ""
else
sPath = WScript.Arguments(1)
End If
importModulesTxt sADPFilename, sPath
If (Err <> 0) and (Err.Description <> NULL) Then
MsgBox Err.Description, vbExclamation, "Error"
Err.Clear
End If
Function importModulesTxt(sADPFilename, sImportpath)
Dim myComponent
Dim sModuleType
Dim sTempname
Dim sOutstring
' Build file and pathnames
dim myType, myName, myPath, sStubADPFilename
myType = fso.GetExtensionName(sADPFilename)
myName = fso.GetBaseName(sADPFilename)
myPath = fso.GetParentFolderName(sADPFilename)
' if no path was given as argument, use a relative directory
If (sImportpath = "") then
sImportpath = myPath & "\Source\"
End If
sStubADPFilename = sImportpath & myName & "_stub." & myType
' check for existing file and ask to overwrite with the stub
if (fso.FileExists(sADPFilename)) Then
WScript.StdOut.Write sADPFilename & " existiert bereits. �berschreiben? (j/n) "
dim sInput
sInput = WScript.StdIn.Read(1)
if (sInput <> "j") Then
WScript.Quit
end if
fso.CopyFile sADPFilename, sADPFilename & ".bak"
end if
fso.CopyFile sStubADPFilename, sADPFilename
' launch MSAccess
WScript.Echo "starting Access..."
Dim oApplication
Set oApplication = CreateObject("Access.Application")
WScript.Echo "opening " & sADPFilename & " ..."
If (Right(sStubADPFilename,4) = ".adp") Then
oApplication.OpenAccessProject sADPFilename
Else
oApplication.OpenCurrentDatabase sADPFilename
End If
oApplication.Visible = false
Dim folder
Set folder = fso.GetFolder(sImportpath)
' load each file from the import path into the stub
Dim myFile, objectname, objecttype
for each myFile in folder.Files
objecttype = fso.GetExtensionName(myFile.Name)
objectname = fso.GetBaseName(myFile.Name)
WScript.Echo " " & objectname & " (" & objecttype & ")"
if (objecttype = "form") then
oApplication.LoadFromText acForm, objectname, myFile.Path
elseif (objecttype = "bas") then
oApplication.LoadFromText acModule, objectname, myFile.Path
elseif (objecttype = "mac") then
oApplication.LoadFromText acMacro, objectname, myFile.Path
elseif (objecttype = "report") then
oApplication.LoadFromText acReport, objectname, myFile.Path
end if
next
oApplication.RunCommand acCmdCompileAndSaveAllModules
oApplication.Quit
End Function
Public Function getErr()
Dim strError
strError = vbCrLf & "----------------------------------------------------------------------------------------------------------------------------------------" & vbCrLf & _
"From " & Err.source & ":" & vbCrLf & _
" Description: " & Err.Description & vbCrLf & _
" Code: " & Err.Number & vbCrLf
getErr = strError
End Function
' Usage:
' CScript decompose.vbs <input file> <path>
' Converts all modules, classes, forms and macros from an Access Project file (.adp) <input file> to
' text and saves the results in separate files to <path>. Requires Microsoft Access.
'
Option Explicit
' FileSystemObject.CreateTextFile and FileSystemObject.OpenTextFile
Const OpenAsASCII = 0
Const OpenAsUnicode = -1
' FileSystemObject.CreateTextFile
Const OverwriteIfExist = -1
Const FailIfExist = 0
' FileSystemObject.OpenTextFile
Const OpenAsDefault = -2
Const CreateIfNotExist = -1
Const FailIfNotExist = 0
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
const acForm = 2
const acModule = 5
const acMacro = 4
const acReport = 3
' BEGIN CODE
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
dim sADPFilename
If (WScript.Arguments.Count = 0) then
MsgBox "Bitte den Dateinamen angeben!", vbExclamation, "Error"
Wscript.Quit()
End if
sADPFilename = fso.GetAbsolutePathName(WScript.Arguments(0))
Dim sExportpath
If (WScript.Arguments.Count = 1) then
sExportpath = ""
else
sExportpath = WScript.Arguments(1)
End If
exportModulesTxt sADPFilename, sExportpath
If (Err <> 0) and (Err.Description <> NULL) Then
MsgBox Err.Description, vbExclamation, "Error"
Err.Clear
End If
' Based on https://github.com/bkidwell/msaccess-vcs-integration/blob/master/AppCodeImportExport.bas
' Sanitizes MS Access output and converts to ASCII for Git.
Function Sanitize(inFileName, outFileName)
Dim inFile, outFile, txt, AggressiveSanitize, inFileObj
AggressiveSanitize = True
Set inFile = fso.OpenTextFile(inFileName, ForReading, FailIfNotExist, OpenAsDefault)
Set outFile = fso.CreateTextFile(outFileName, OverwriteIfExist, OpenAsASCII)
Set inFileObj = fso.GetFile(inFileName)
If inFileObj.Size > 0 Then
Do
txt = InFile.ReadLine
If Left(txt, 10) = "Checksum =" Then
' Skip lines starting with Checksum
ElseIf InStr(txt, "NoSaveCTIWhenDisabled =1") Then
' Skip lines containning NoSaveCTIWhenDisabled
ElseIf InStr(txt, "Begin") > 0 Then
If _
InStr(txt, "PrtDevNames =") > 0 Or _
InStr(txt, "PrtDevNamesW =") > 0 Or _
InStr(txt, "PrtDevModeW =") > 0 Or _
InStr(txt, "PrtDevMode =") > 0 _
Then
' skip this block of code
Do Until InFile.AtEndOfStream
txt = InFile.ReadLine
If InStr(txt, "End") Then Exit Do
Loop
ElseIf AggressiveSanitize And ( _
InStr(txt, "dbLongBinary ""DOL"" =") > 0 Or _
InStr(txt, "NameMap") > 0 Or _
InStr(txt, "GUID") > 0 _
) Then
' skip this block of code
Do Until InFile.AtEndOfStream
txt = InFile.ReadLine
If InStr(txt, "End") Then Exit Do
Loop
Else
' This block will be outputted, so output Begin
OutFile.WriteLine txt
End If
Else
OutFile.WriteLine txt
End If
Loop Until inFile.AtEndOfStream
End If
inFile.Close
outFile.Close
End Function
Function exportModulesTxt(sADPFilename, sExportpath)
Dim myComponent
Dim sModuleType
Dim sTempname
Dim sOutstring
dim myType, myName, myPath, sStubADPFilename
myType = fso.GetExtensionName(sADPFilename)
myName = fso.GetBaseName(sADPFilename)
myPath = fso.GetParentFolderName(sADPFilename)
If (sExportpath = "") then
sExportpath = myPath & "\Source\"
End If
sStubADPFilename = sExportpath & myName & "_stub." & myType
WScript.Echo "copy stub to " & sStubADPFilename & "..."
On Error Resume Next
fso.CreateFolder(sExportpath)
On Error Goto 0
fso.CopyFile sADPFilename, sStubADPFilename
WScript.Echo "starting Access..."
Dim oApplication
Set oApplication = CreateObject("Access.Application")
WScript.Echo "opening " & sStubADPFilename & " ..."
If (Right(sStubADPFilename,4) = ".adp") Then
oApplication.OpenAccessProject fso.GetAbsolutePathName(sStubADPFilename)
Else
oApplication.OpenCurrentDatabase fso.GetAbsolutePathName(sStubADPFilename)
End If
oApplication.Visible = false
dim dctDelete
Set dctDelete = CreateObject("Scripting.Dictionary")
WScript.Echo "exporting..."
Dim myObj
Dim tempOutPath, finalOutPath
For Each myObj In oApplication.CurrentProject.AllForms
WScript.Echo " " & myObj.fullname
tempOutPath = sExportpath & "\" & fso.GetTempName
oApplication.SaveAsText acForm, myObj.fullname, tempOutPath
oApplication.DoCmd.Close acForm, myObj.fullname
dctDelete.Add "FO" & myObj.fullname, acForm
finalOutPath = sExportpath & "\" & myObj.fullname & ".form"
Sanitize tempOutPath, finalOutPath
fso.DeleteFile tempOutPath, True
Next
For Each myObj In oApplication.CurrentProject.AllModules
WScript.Echo " " & myObj.fullname
tempOutPath = sExportpath & "\" & fso.GetTempName
oApplication.SaveAsText acModule, myObj.fullname, tempOutPath
dctDelete.Add "MO" & myObj.fullname, acModule
finalOutPath = sExportpath & "\" & myObj.fullname & ".bas"
Sanitize tempOutPath, finalOutPath
fso.DeleteFile tempOutPath, True
Next
For Each myObj In oApplication.CurrentProject.AllMacros
WScript.Echo " " & myObj.fullname
tempOutPath = sExportpath & "\" & fso.GetTempName
oApplication.SaveAsText acMacro, myObj.fullname, tempOutPath
dctDelete.Add "MA" & myObj.fullname, acMacro
finalOutPath = sExportpath & "\" & myObj.fullname & ".mac"
Sanitize tempOutPath, finalOutPath
fso.DeleteFile tempOutPath, True
Next
For Each myObj In oApplication.CurrentProject.AllReports
WScript.Echo " " & myObj.fullname
tempOutPath = sExportpath & "\" & fso.GetTempName
oApplication.SaveAsText acReport, myObj.fullname, tempOutPath
dctDelete.Add "RE" & myObj.fullname, acReport
finalOutPath = sExportpath & "\" & myObj.fullname & ".report"
Sanitize tempOutPath, finalOutPath
fso.DeleteFile tempOutPath, True
Next
WScript.Echo "deleting..."
dim sObjectname
For Each sObjectname In dctDelete
WScript.Echo " " & Mid(sObjectname, 3)
oApplication.DoCmd.DeleteObject dctDelete(sObjectname), Mid(sObjectname, 3)
Next
oApplication.CloseCurrentDatabase
oApplication.CompactRepair sStubADPFilename, sStubADPFilename & "_"
oApplication.Quit
fso.CopyFile sStubADPFilename & "_", sStubADPFilename
fso.DeleteFile sStubADPFilename & "_"
End Function
Public Function getErr()
Dim strError
strError = vbCrLf & "----------------------------------------------------------------------------------------------------------------------------------------" & vbCrLf & _
"From " & Err.source & ":" & vbCrLf & _
" Description: " & Err.Description & vbCrLf & _
" Code: " & Err.Number & vbCrLf
getErr = strError
End Function
#!/bin/bash
# Only invoke meld if the files have differences worth seeing. Otherwise, favor
# remote copy to eliminate case-differences.
BASE=$1
LOCAL=$2
REMOTE=$3
MERGED=$4
diff --ignore-case --ignore-trailing-space "$LOCAL" "$REMOTE"
if [[ $? == 0 ]]; then
echo "Only case differences. Favoring REMOTE."
cp -f "$REMOTE" "$MERGED"
exit 0
else
meld "$LOCAL" "$BASE" "$REMOTE" --output="$MERGED"
exit $?
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment