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
- To run the project, run following in the target folder (testfolder for testing our project):
go run ../cmd/cli/main.go {command}
- 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
To test specific function in a module, run:
go test github.com/machichima/vcs-go/cmd/cli/utils -v -run function
-
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
-
Track difference between current files and previous commit
- used in stage function
-
Combine the filetree from new and old commit to form a new one
- always save the newest full filetree of the project
-
add
-
status
-
commit
-
log
-
Write test (functional test)
- add
- status
- commit
- log
-
rm
-
checkout
- checkout branch
-
branch
-
branch -d (delete branch)
-
merge
-
remote option ...
- Finish create branch:
branch
- Finish delete branch:
branch -d
- Finish checkout branch
- Finish
checkout
command - Finish tests for
checkout
- finish functional test for add / status / rm / commit / log commands
- finish rm command
- Finish until log function
- update filetree based on index and prev filetree
- Track difference between current files and previous commit
- used in stage function
- Combine the filetree from new and old commit to form a new one
- always save the newest full filetree of the project
- Finish status command
- Finish commit command
- Finish log command
- Finish the add function
- Finish Serialization function for the file contents
- Get the files with their directory structure