-
Notifications
You must be signed in to change notification settings - Fork 703
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #707 from pjbgf/experimental-sha256
*: Add support for initializing SHA256 repositories
- Loading branch information
Showing
23 changed files
with
298 additions
and
60 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
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/go-git/go-git/v5" | ||
. "github.com/go-git/go-git/v5/_examples" | ||
"github.com/go-git/go-git/v5/plumbing/format/config" | ||
"github.com/go-git/go-git/v5/plumbing/object" | ||
) | ||
|
||
// This example requires building with the sha256 tag for it to work: | ||
// go run -tags sha256 main.go /tmp/repository | ||
|
||
// Basic example of how to initialise a repository using sha256 as the hashing algorithmn. | ||
func main() { | ||
CheckArgs("<directory>") | ||
directory := os.Args[1] | ||
|
||
os.RemoveAll(directory) | ||
|
||
// Init a new repository using the ObjectFormat SHA256. | ||
r, err := git.PlainInitWithOptions(directory, &git.PlainInitOptions{ObjectFormat: config.SHA256}) | ||
CheckIfError(err) | ||
|
||
w, err := r.Worktree() | ||
CheckIfError(err) | ||
|
||
// ... we need a file to commit so let's create a new file inside of the | ||
// worktree of the project using the go standard library. | ||
Info("echo \"hello world!\" > example-git-file") | ||
filename := filepath.Join(directory, "example-git-file") | ||
err = ioutil.WriteFile(filename, []byte("hello world!"), 0644) | ||
CheckIfError(err) | ||
|
||
// Adds the new file to the staging area. | ||
Info("git add example-git-file") | ||
_, err = w.Add("example-git-file") | ||
CheckIfError(err) | ||
|
||
// Commits the current staging area to the repository, with the new file | ||
// just created. We should provide the object.Signature of Author of the | ||
// commit Since version 5.0.1, we can omit the Author signature, being read | ||
// from the git config files. | ||
Info("git commit -m \"example go-git commit\"") | ||
commit, err := w.Commit("example go-git commit", &git.CommitOptions{ | ||
Author: &object.Signature{ | ||
Name: "John Doe", | ||
Email: "john@doe.org", | ||
When: time.Now(), | ||
}, | ||
}) | ||
|
||
CheckIfError(err) | ||
|
||
// Prints the current HEAD to verify that all worked well. | ||
Info("git show -s") | ||
obj, err := r.CommitObject(commit) | ||
CheckIfError(err) | ||
|
||
fmt.Println(obj) | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package config | ||
|
||
// RepositoryFormatVersion represents the repository format version, | ||
// as per defined at: | ||
// | ||
// https://git-scm.com/docs/repository-version | ||
type RepositoryFormatVersion string | ||
|
||
const ( | ||
// Version_0 is the format defined by the initial version of git, | ||
// including but not limited to the format of the repository | ||
// directory, the repository configuration file, and the object | ||
// and ref storage. | ||
// | ||
// Specifying the complete behavior of git is beyond the scope | ||
// of this document. | ||
Version_0 = "0" | ||
|
||
// Version_1 is identical to version 0, with the following exceptions: | ||
// | ||
// 1. When reading the core.repositoryformatversion variable, a git | ||
// implementation which supports version 1 MUST also read any | ||
// configuration keys found in the extensions section of the | ||
// configuration file. | ||
// | ||
// 2. If a version-1 repository specifies any extensions.* keys that | ||
// the running git has not implemented, the operation MUST NOT proceed. | ||
// Similarly, if the value of any known key is not understood by the | ||
// implementation, the operation MUST NOT proceed. | ||
// | ||
// Note that if no extensions are specified in the config file, then | ||
// core.repositoryformatversion SHOULD be set to 0 (setting it to 1 provides | ||
// no benefit, and makes the repository incompatible with older | ||
// implementations of git). | ||
Version_1 = "1" | ||
|
||
// DefaultRepositoryFormatVersion holds the default repository format version. | ||
DefaultRepositoryFormatVersion = Version_0 | ||
) | ||
|
||
// ObjectFormat defines the object format. | ||
type ObjectFormat string | ||
|
||
const ( | ||
// SHA1 represents the object format used for SHA1. | ||
SHA1 ObjectFormat = "sha1" | ||
|
||
// SHA256 represents the object format used for SHA256. | ||
SHA256 ObjectFormat = "sha256" | ||
|
||
// DefaultObjectFormat holds the default object format. | ||
DefaultObjectFormat = SHA1 | ||
) |
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
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
Oops, something went wrong.