Detailed explanation of the long instruction of git under Python enhancement
- 2021-12-04 10:21:07
- OfStack
Introduction to Git
I believe everyone has used SVN, but SVN will be limited by the network. When I joined a company before, there were many things on SVN that needed check out, which were extremely affected by the network and sometimes interrupted, and the efficiency was very low. While Git has the advantages of SVN, it can solve this problem perfectly. This is also the difference between centralized and distributed version control systems
CVS and SVN are both centralized version control systems, while Git is a distributed version control system.
Scene
Now a little size of the company are using GitFlow mode for branch management, although plug-ins bring us great convenience, but switch branch, find branch, branch is still so troublesome
Demand
In the primary and secondary countries of society, every working people living at the bottom, they work silently, all kinds of 996, multi-thread work
beta
dev
develop
effectiveJava
feature/20210712-reviewOpenApi
feature/20210727-tapd-1003358
feature/20210824-tapd-1004652
feature/20210909-tapd-1005586
feature/20210913-tapd-1005758
hotfix/20210915-fix-gainPointForGiftCard
master
* test
Every code farmer colleagues are carrying out a lot of needs, in order to make our work more efficient! We also give ourselves a few needs!
Set up quicklyhotfix/feature
Branching
Quickly switch to specified working branches among numerous local branches
Clearly describe the task description corresponding to each branch
.......
For this reason, the idea of enhancing the native git has long appeared, but one has not written ~, so I will use Python to upgrade today!
Under development
Code directory structure
> tree
-- README.MD
-- __init__.py
-- cmdDict.py
-- command
The -- __init__.py
The -- commandStrategy.py
The -- createTaskStrategy.py
The -- gitCmdStrategy.py
The -- gtaskHelp.py
The -- printCurrentBrStrategy.py
The Off- switchBranch.py
-- gtaskContext.py
-- main.py
Off- support
-- __init__.py
-- breancEntity.py
-- clientCommand.py
Off- parseError.py
main.py
Is an entry function
cmdDict.py
The file is a configuration file
command
The directory is stored in the specific command implementation
support
Directory for 1 Supported Classes
cmdDict.py
Documents
from command import printCurrentBrStrategy,gtaskHelp,createTaskStrategy,switchBranch,gitCmdStrategy
"""
The command interpreter corresponding to the following instructions is configured here
"""
cmd = {
"-b": printCurrentBrStrategy.PrintBr(),
"--help": gtaskHelp.GtaskHelper(),
"-c":createTaskStrategy.CreateTask(),
"--co":switchBranch.SwitchBranch()
}
"""
Special configuration, parsing git The command of
"""
git = {
"git": gitCmdStrategy.GitCmd()
}
Mainly configuration commands and corresponding interpretation script files
September 14th
Establish a warehouse Realize viewing all branches Create a branch, Fast branch switching help informationWhen creating a branch, prompt for task name, description, etc. When viewing all branches, mark the corresponding index number on the branches, switch the specified index number to switch branches, and display the branch description when colleagues display
Savey:baking-apiserver:% g -b <test>
[001] - beta ##beta Branching
[002] - dev
[003] - develop
[004] - effectiveJava
[005] - feature/20210712-reviewOpenApi
[006] - feature/20210727-tapd-1003358 ## Electronic invoice
[007] - feature/20210824-tapd-1004652 ## Pre-sale
[008] - feature/20210909-tapd-1005586 ## Cancel delivery
[009] - feature/20210913-tapd-1005758 ## Printing of discount details of Meituan take-out order
[010] - hotfix/20210915-fix-gainPointForGiftCard
[011] - master ##yes
[012] - test ##test
September 15th
Compatible with native
git
Use
Savey:baking-apiserver:% g version
git version 2.24.3 (Apple Git-128)
Adds a description for the current branch
Well, I forgot to write the description when I first set up the branch, so I will quickly write the description to the branch again without typing it
git config branch.<branchName>.description
It's over
Just like this now
Savey:baking-apiserver:% g --desc test Branching
✅Success!!
September 16th
Because there will be more and more instructions, before in
cmdDict.py
It is not appropriate to configure the specified command directly. Today, it was changed to the following writing. Use the features of the generator to improve the little performance, because before that, my old family
php
Also support
main.py
0
. So today the index to modify it! By the way
cmdDIct.py
Change one's name
Config.py
Isn't it better?
Take the previous instructions to the specific class to implement.
def keyCommand():
yield printCurrentBrStrategy.PrintBr()
yield gtaskHelp.GtaskHelper()
yield createTaskStrategy.CreateTask()
yield switchBranch.SwitchBranch()
yield editBrDesc.EditBrDesc()
In abstract classes
AbstractCommandStrategy.py
Adding method
"""
Implementation method of stored instruction
"""
@abstractmethod
def command(self):
pass
Configure the corresponding subclass by specific subclasses
command
Orders. For example
from . import commandStrategy
class PrintBr(commandStrategy.AbstractCommandStrategy):
"""
Configured here Specified instruction
"""
def command(self):
return "-b"
def cmd(self, args):
super().printAllBr(args)
def useage(self):
print(self.command() + "\t Print out all current branches, list index numbers and descriptions ")
pass
Try to take a small step on the first day
Code in GitHub