Skip to content

Latest commit

 

History

History
172 lines (138 loc) · 4.35 KB

README.md

File metadata and controls

172 lines (138 loc) · 4.35 KB

vcs-go

Introduction

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

  • 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

Usage

Run

  • To run the project, run following in the target folder (testfolder for testing our project):
go run ../cmd/cli/main.go {command}

Test

  • 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

TODO

  • 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 ...

Work Log

12/10/2024

  • Finish create branch: branch
  • Finish delete branch: branch -d
  • Finish checkout branch

11/10/2024

  • Finish checkout command
  • Finish tests for checkout

07/10/2024

  • finish functional test for add / status / rm / commit / log commands

26/09/2024

  • finish rm command

25/09/2-24

  • Finish until log function
    • update filetree based on index and prev filetree

13/09/2024

  • 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

12/09/2024

  • Finish status command
  • Finish commit command
  • Finish log command

Before 12/09/2024

  • Finish the add function

27/07/2024

  • Finish Serialization function for the file contents
  • Get the files with their directory structure