Using Git with VB6
Asked Answered
M

9

29

Our company has a large codebase in VB6, and we currently use VSS which, for all that we hate about it, at least integrates into the VB6 IDE.

My own team, which is using .NET, are now looking into alternative SCMs like my personal favourite, Git. With Git Extensions, it seems we will be able to integrate Git commands into the Visual Studio IDE pretty well.

However, the question has been asked: could Git be used for our VB6 codebase too?

Of course I assume the files themselves would work fine in git repositories, but no doubt developers would complain if they had to use the command-line to do all their source control. But has anyone had any experience using VB6 and Git? Any integration available from within the VB6 IDE? Or is it perhaps not that much of a hassle to not have the IDE integration?

And do I get a badge for being the first to create the absurd tag combination of [vb6] and [git]?

Meanwhile answered 17/3, 2010 at 13:21 Comment(2)
personally I don't tend to like IDE integration other than to report status (green lights etc), I have never a substitute that I personally prefer inside an IDE they all tend to be third party programs, shell integrated or my personal favourite, the command line. And yes you should definately get a badge for creating a vb6 and git tag :)Borowski
vb6 and git in the same sentence? yes, definitely deserves a badgeGoose
V
26

I found this solution to work in our situation. It adds a bit more to the previous answers and solved all of our MANY issues getting our project to work with git.

.gitattributes

# Set the default behavior, in case people don't have core.autocrlf set.
* text eol=auto
*.bas text eol=crlf
*.frm text eol=crlf
*.log text eol=crlf
*.vbp text eol=crlf
*.cls text eol=crlf
*.vbw text eol=crlf
*.dsr text eol=crlf
*.ini text eol=crlf
*.res binary
*.RES binary
*.frx binary
*.exe binary
*.dll binary
*.ico binary
*.gif binary
*.ocx binary
*.tlb binary
*.ocx.bin binary
*.ism binary
*.bin binary
*.aps binary
*.ncb binary
*.exe.compat binary
*.ocx.compat binary

.gitignore

.DS_Store
.Trashes
*.vbw
*.csi
*.exp
*.lib
*.lvw
*.dca
*.scc
*.tmp
<name of built binary, exe, dll or ocx>
Venusberg answered 18/5, 2016 at 22:35 Comment(1)
Thanks for this answer it really helped. You should also add: *.vbg text eol=crlf *.ctl text eol=crlf *.pag text eol=crlf to .gitattributes to cover project groups, custom controls and property pagesLash
S
10

Been using Git to manage VB6 projects for about a year now. Never came across any IDE integration. Personally I like the command line, so I've not been looking much. The two major issues I've encountered are:

  1. VB6 IDE doesn't monitor the project files, if any of them is changed externally (e.g. using 'git reset', 'git checkout') then the project needs to be re-opened to reflect the changes.
  2. VB6 IDE will sometimes change the case of event parameters or variables when loading a project, so it's never safe to use 'git commit --all' unless you want a lot of garbage with your code changes.
Syncopated answered 8/4, 2010 at 7:46 Comment(0)
C
9

You have to create the file .gitattributes to use windows line endings (crlf) because git was born in unix.

# Declare files that will always have CRLF line endings on checkout.
*.vbp text eol=crlf
*.frm text eol=crlf
*.cls text eol=crlf
*.bas text eol=crlf
*.dsr text eol=crlf
*.ini text eol=crlf

# Denote all files that are truly binary and should not be modified.
*.frx binary
*.exe binary
*.dll binary
*.ocx binary

Also create .gitignore file with the following lines:

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.vbw
*.tmp
*.scc
*.dca
Clavate answered 6/2, 2016 at 15:1 Comment(2)
what kind of temporary files are *.dca?Marketplace
".dca" files are Data Dynamics Active Reports temporary files.Clavate
C
8

This really is an addition to the other excellent comments by KeithTheBiped, et al...

But, it is possible to somewhat coerce the Immediate Window in VB6 to act like a modern terminal window, with some caveats. If we create a helper function to run the command, capture the output somehow, and then use Debug.Print to relay that back to the Immediate window SIMILAR to the terminal window, but without any interactive elements, of course.

This works for most commands, but fails to capture some of the output in the git push phase. An acceptable compromise, for the convenience of no shell (imo).

We can do just that using the the command prompt (cmd.exe /c) using the 1> and 2> pipes aimed at temporary files. I don't supply a couple underlying functions, but provide sources if you don't have them already.

Consider the following function:

Public Function RunCmdToOutput(ByVal cmd As String, Optional ByRef ErrStr As String = "") As String
Const p_enSW_HIDE = 0

On Error GoTo RunError

  Dim A As String, B As String
  A = TempFile
  B = TempFile

  ShellAndWait "cmd /c " & cmd & " 1> " & A & " 2> " & B, p_enSW_HIDE

  RunCmdToOutput = ReadEntireFileAndDelete(A)
  ErrStr = ReadEntireFileAndDelete(B)

  Exit Function

RunError:
  RunCmdToOutput = ""
  ErrStr = "ShellOut.RunCmdToOutput: Command Execution Error - [" & Err.Number & "] " & Err.Description
End Function

You will need:

  • TempFile - Return a unique and non-existant file-name that your program has read/write access to. It should probably use the GetShortPathName API to shorten long path names.
  • ShellAndWait - The standard "start a process and wait for it to exit".
  • ReadEntireFileAndDelete - Just what it says... Grab the contents, delete the file, return the string.

Once you have accomplished this and can successfully run any simple executing and output into the Immediate window like this:

?runcmdtooutput("ver")
Microsoft Windows [Version 10.0.16299.309]

From here, you can run Git, and display MOST things into the Immediate window, and could use it as simple as that, but we can do better.

Assuming you have already installed a command-line Git and the path is updated so that it is available, you can create a few new functions (hopefully in a module):

Private Function GitCmd(ByVal C As String, Optional ByVal NoOutput As Boolean = False) As String
  Dim ErrSt As String
  GitCmd = RunCmdToOutput(C, ErrSt)
  If Not NoOutput Then Debug.Print GitCmd ' Because it also returns the string
  If ErrSt <> "" Then Debug.Print "ERR: " & ErrSt
End Function

Public Function Git(ByVal C As String) As Boolean
  GitCmd "git " & C
  Git = True
End Function

From here, you can ALMOST run Git commands from the immediate window. Remember, Git() is a function, so you have to pass in the argument as a string... Just one necessary character. Of course, VB will auto-complete a string, so you don't NEED the trailing quite, but I'll include it. Use the syntax:

Git "status"
Git "add ."
Git "commit -m ""Some Git Commit"""
Git "pull -r"
Git "push"

It doesn't allow interactive git commands (git add -p), but, you could just brute-force it (git add . -f). But, the commands run and directly display their output into the Immediate window without much other effort.

git "status"
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
...

You get the idea.

From there, you can also automate things. Create helper functions to batch commonly used Git commands, etc, or just eliminate some of the clunky syntax. With RunCmdToOutput, you can also re-work some of it to use the MsgBox, if preferred, but I thought the Immediate Window was intuitive enough.

It might also be important at some point to restrict any functions to only run in the IDE, but that's optional.

Public Function IsIDE() As Boolean
  On Error GoTo IDEInUse
  Debug.Print 1 \ 0 'division by zero error - Debug is ignored by compile
  IsIDE = False
  Exit Function
IDEInUse:
  IsIDE = True
End Function

Public Function GitStatus()
  If Not IsIDE Then Exit Function
  GitCmd "git status"
  GitStatus = True
End Function
Ciracirca answered 4/4, 2018 at 22:13 Comment(1)
As a side note, while I have used a variant of the above, it does require something on the order of a function such as RestartIDE(), which I also use whenever I do a git pull -r. It performs a new startup of the IDE and does an API KillProcess() on the current one... A bit barbaric, no doubt... Make sure you save any changes first... But, since VB6 doesn't reload files changed outside the IDE, and plugins like VB Accelerator don't detect changes made from Git when it it launched from the Immediate Window, a bit of rough handling does appear to be necessary to detect file changes.Ciracirca
P
5

You know your developers best. Will they mind using the command line? Are they keen on IDE integration? These are personal preferences.

Make sure the most respected developers understand the benefits of git and are behind the decision.

Do be aware that some VB6 source files are binary and shouldn't ever be merged: e.g. .frx files. I don't know git, so I don't know whether that's a problem.

Pericarditis answered 17/3, 2010 at 16:10 Comment(0)
G
3

What's so different about VB6 as a code base (i.e. text files) that makes it not suitable for git?

The culture is another matter altogether: if you have plenty of incompetent developers who can't handle the command line, the cure would probably include running away from VB6 as far as you can.

The only potential problem is that windows in the git world is somewhat of a second class citizen. You might wanna try bazaar or mercurial if you find git doesn't work very well in your environment.

Goose answered 17/3, 2010 at 15:5 Comment(3)
if you use msysgit on windows then you shouldn't have a problem with being a 2nd class citizen. I use it to connect to TFS (via SVNBridge and then git-svn) and dont have any problems with it (except the speed of SVNBridge). Historically this may be true but not so much now.Albumin
So VB6 just has to be a SOB.Goose
Other languages are just so primitive, based on 1950s programming technology.Bedside
F
3

We are doing this. We have added the following to .gitIgnore

  • *.csi
  • *.exp
  • *.lib
  • *.lvw
  • *.vbw
  • MyProject.dll
Ferren answered 11/1, 2016 at 19:15 Comment(0)
E
2

I am using Atlassian Source tree to manage my VB6 projects in git repositories. Works fine.

As mentioned, one hurdle is that when an identifier is defined in the IDE, the IDE goes off and changes the case of matching identifiers and these produce screeds of changes that are all spurious.

The solution is to keep a block of identifiers in a text file and slap them into the (General) (Declarations) part of each file as needed like this:

#If False Then
    Dim Index 
    Dim T 
    Dim Ctrl
    Dim C 
#End If

This will force all instances of index to be Index, etc. If you get a bunch of IDE edits appearing as code changes, you simply paste in the standard casing, and save the file again.

Elicia answered 27/3, 2022 at 2:42 Comment(2)
Thanks for the tip about the case changes, we have the same issue but work around it with a (complicated) script which compares a staged file to the original and reverts all the case changes to the original.Meanwhile
@Meanwhile That sounds nice. Would you mind shaing this script?Ultra
G
1

there is a solution for the old VB6-IDE, VC6-IDE that uses the MSSCCI and can integrate in every IDE providing MSSCC interface for source control. you find it here Visual Git.

Gorges answered 20/7, 2023 at 13:33 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Questor

© 2022 - 2025 — McMap. All rights reserved.