This is the Go version of Gitlet from this project written in JAVA. I try to follow all the concept in this project and reproduce in Go.
-
store files / metadata in
.vgo/
folder -
commands
init
add
status
commit
rm
- unstage the file
log
- show the history of current node
checkout
- file: take out the file from the HEAD commit to the working directory
- commit_id file: take out the file from the specific commit to the working directory
- (advanced) branch_name: switch to the branch
- (advanced) other commands for branch -> refer to external link for detail
- File structure for the project is as follows:
.
├── cmd
│ └── cli
│ ├── commands
│ │ ├── init.go
│ │ └── root.go
│ ├── main.go
│ └── utils
│ ├── file.go
│ └── serialize.go
├── go.mod
├── go.sum
├── README.md
└── testfolder
Test for each file are included in the same folder as the file itself.
-
utils
: tool functions -
commands
: each commands shown in Introduction has its own folder -
The committed files are stored in
.vgo/objects
folder. The file structure is as follows:
/my_project
.vgo
/objects
6a/
7f3 # Serialized content of a blob with hash starting with 6a7f3...
2f/
4f2 # Serialized content of a tree with hash starting with 2f4f2...
d1/
2f5 # Serialized content of a commit with hash starting with d12f5...
/refs
/heads
main # Pointer to the latest commit on the main branch
HEAD # Pointer to the current commit checked out
- Go to the folder of the file you want to test, run following:
go test
To see more details of the test, run:
go test -v
- init
- create .vcsgo folder with empty structures inside
- Detect if .vcsgo folder already exists
- Serialization
- files into blob
- Serialize the file blob and deserialize
- Hash the file blob
- file tree into blob
- Get file with directory structure
- hashmap for file dir structure to SHA-1 hash of the file
- commit into blob
- SHA-1 hashing function
- Hash from serialized objects -> get hash string
- Store hash string in .vcsgo/objects
- add
- commit
- log
- checkout
- rm
- branch operation...
- Finish Serialization function for the file contents
- Get the files with their directory structure