VCS_Git.bas 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. Option Compare Database
  2. Public Function is_git_repo() As Boolean
  3. ' returns True if current app dir is a git repository
  4. is_git_repo = (dir(CurrentProject.path & "\.git\", vbDirectory) <> "")
  5. End Function
  6. Public Function gitcmd(args)
  7. ' run a git command on windows (eg: `gitcmd("add *")` )
  8. Call cmd("echo -- " & args & " -- & git " & args & "& pause", vbNormalFocus)
  9. End Function
  10. Public Function complete_gitignore()
  11. ' creates or complete the .gitignore file of the repo
  12. Dim gitignore_path, str_existing_keys, str As String
  13. Dim keys() As String
  14. keys = Split("*.accdb;*.laccdb;*.mdb;*.ldb;*.accde;*.mde;*.accda", ";")
  15. gitignore_path = CurrentProject.path & "\.gitignore"
  16. Dim fso As Object
  17. Set fso = CreateObject("Scripting.FileSystemObject")
  18. Dim oFile As Object
  19. If Not fso.FileExists(gitignore_path) Then
  20. Set oFile = fso.CreateTextFile(gitignore_path)
  21. Else
  22. Set oFile = fso.OpenTextFile(gitignore_path, ForReading)
  23. str_existing_keys = ""
  24. While Not oFile.AtEndOfStream
  25. str = oFile.readline
  26. If Len(str_existing_keys) = 0 Then
  27. str_existing_keys = str
  28. Else
  29. str_existing_keys = str_existing_keys & ";" & str
  30. End If
  31. Wend
  32. oFile.Close
  33. Dim existing_keys() As String
  34. existing_keys = Split(str_existing_keys, ";")
  35. Set oFile = fso.OpenTextFile(gitignore_path, ForAppending)
  36. End If
  37. oFile.WriteBlankLines (2)
  38. oFile.WriteLine ("#[ automatically added by VCS")
  39. For Each key In keys
  40. If Not IsInArray(key, existing_keys) Then
  41. oFile.WriteLine key
  42. End If
  43. Next key
  44. oFile.WriteLine "#]"
  45. oFile.WriteBlankLines (2)
  46. oFile.Close
  47. Set fso = Nothing
  48. Set oFile = Nothing
  49. End Function