-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c54b545
commit 8a8a53d
Showing
9 changed files
with
284 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/richardjennings/mygit/internal/mygit" | ||
"github.com/spf13/cobra" | ||
"log" | ||
) | ||
|
||
var logCmd = &cobra.Command{ | ||
Use: "log", | ||
Args: cobra.ExactArgs(0), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if err := configure(); err != nil { | ||
log.Fatalln(err) | ||
} | ||
return mygit.Log() | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(logCmd) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ package mygit | |
import ( | ||
"errors" | ||
"fmt" | ||
"github.com/richardjennings/mygit/internal/mygit/commits" | ||
"github.com/richardjennings/mygit/internal/mygit/config" | ||
"github.com/richardjennings/mygit/internal/mygit/fs" | ||
"github.com/richardjennings/mygit/internal/mygit/index" | ||
|
@@ -34,6 +33,27 @@ func Init() error { | |
return os.WriteFile(config.GitHeadPath(), []byte(fmt.Sprintf("ref: %s\n", config.Config.DefaultBranch)), 0644) | ||
} | ||
|
||
// Log prints out the commit log for the current branch | ||
func Log() error { | ||
branch, err := refs.CurrentBranch() | ||
if err != nil { | ||
return err | ||
} | ||
commitSha, err := refs.HeadSHA(branch) | ||
if err != nil { | ||
return err | ||
} | ||
commit, err := objects.ReadCommit(commitSha) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("tree: %s\n", string(commit.Tree)) | ||
for _, v := range commit.Parents { | ||
fmt.Printf("parent: %s\n", string(v)) | ||
} | ||
return nil | ||
} | ||
|
||
// Add adds one or more file paths to the Index. | ||
func Add(paths ...string) error { | ||
idx, err := index.ReadIndex() | ||
|
@@ -104,12 +124,12 @@ func Commit() ([]byte, error) { | |
} | ||
// git has the --allow-empty flag which here defaults to true currently | ||
// @todo check for changes to be committed. | ||
previousCommits, err := commits.PreviousCommits() | ||
previousCommits, err := refs.PreviousCommits() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return commits.Write( | ||
&commits.Commit{ | ||
return objects.WriteCommit( | ||
&objects.Commit{ | ||
Tree: tree, | ||
Parents: previousCommits, | ||
Author: "Richard Jennings <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.