问题
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]?
回答1:
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>
回答2:
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:
- 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.
- 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.
回答3:
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
回答4:
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.
回答5:
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.
回答6:
We are doing this. We have added the following to .gitIgnore
- *.csi
- *.exp
- *.lib
- *.lvw
- *.vbw
- MyProject.dll
回答7:
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
来源:https://stackoverflow.com/questions/2462480/using-git-with-vb6