Skip to content

Commit

Permalink
go.mod: update to pkg/git v0.7.3
Browse files Browse the repository at this point in the history
Fixes #129
  • Loading branch information
zombiezen committed Dec 13, 2020
1 parent 72de42b commit 1e8c13b
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ The format is based on [Keep a Changelog][], and this project adheres to
([#125](https://github.com/gg-scm/gg/issues/125))
- Released binaries are smaller: they no longer contain debug information.
([#121](https://github.com/gg-scm/gg/issues/121))
- `commit --amend` no longer exits with an error if the commit contains a
rename. ([#129](https://github.com/gg-scm/gg/issues/129))

## [1.0.3][] - 2020-09-07

Expand Down
91 changes: 91 additions & 0 deletions cmd/gg/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,97 @@ func TestCommit_AmendRootCommit(t *testing.T) {
}
}

func TestCommit_AmendRename(t *testing.T) {
// Regression test for https://github.com/gg-scm/gg/issues/129

t.Parallel()
ctx := context.Background()
env, err := newTestEnv(ctx, t)
if err != nil {
t.Fatal(err)
}
if err := env.initEmptyRepo(ctx, "."); err != nil {
t.Fatal(err)
}

// Create the first commit with foo.txt.
err = env.root.Apply(
filesystem.Write("foo.txt", dummyContent),
)
if err != nil {
t.Fatal(err)
}
if err := env.addFiles(ctx, "foo.txt"); err != nil {
t.Fatal(err)
}
parent, err := env.newCommit(ctx, ".")
if err != nil {
t.Fatal(err)
}

// Create a second commit that moves foo.txt to bar.txt.
// This is the commit that will be amended.
if err := env.git.Run(ctx, "mv", "foo.txt", "bar.txt"); err != nil {
t.Fatal(err)
}
r1, err := env.newCommit(ctx, ".")
if err != nil {
t.Fatal(err)
}

// Arrange working copy changes.
const modifiedContent = dummyContent + "aaa\n"
err = env.root.Apply(
filesystem.Write("bar.txt", modifiedContent),
)
if err != nil {
t.Fatal(err)
}

// Call gg to make a commit.
const wantMessage = "gg amended this commit\n"
if _, err := env.gg(ctx, env.root.String(), "commit", "--amend", "-m", "gg amended this commit"); err != nil {
t.Fatal(err)
}

// Verify that a new commit was created and has a parent of HEAD~.
changes := map[git.Hash]string{
parent: "parent commit",
r1: "tip",
}
r2, err := env.git.Head(ctx)
if err != nil {
t.Fatal(err)
}
if r2.Commit == r1 {
t.Fatal("commit --amend did not create a new commit in the working copy")
}
if ref := r2.Ref; ref != "refs/heads/main" {
t.Errorf("HEAD ref = %q; want refs/heads/main", ref)
}
if newParent, err := env.git.ParseRev(ctx, "HEAD~"); err != nil {
t.Error(err)
} else if newParent.Commit != parent {
t.Errorf("HEAD~ after amend = %s; want %s",
prettyCommit(newParent.Commit, changes),
prettyCommit(parent, changes))
}

// Verify that the commit incorporated all the changes from the working copy.
if data, err := catBlob(ctx, env.git, r2.Commit.String(), "bar.txt"); err != nil {
t.Error(err)
} else if string(data) != modifiedContent {
t.Errorf("bar.txt = %q; want %q", data, modifiedContent)
}

// Verify that the commit message matches the given message.
if info, err := env.git.CommitInfo(ctx, r2.Commit.String()); err != nil {
t.Error(err)
} else if info.Message != wantMessage {
t.Errorf("commit message = %q; want %q", info.Message, wantMessage)
}
}

func TestCommit_NoChanges(t *testing.T) {
t.Parallel()
ctx := context.Background()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ go 1.14

require (
gg-scm.io/pkg/ghdevice v0.1.0
gg-scm.io/pkg/git v0.7.2
gg-scm.io/pkg/git v0.7.3
github.com/google/go-cmp v0.5.4
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
gg-scm.io/pkg/ghdevice v0.1.0 h1:WF7J5QPL/D9jMCmycpvb87zJceQwsNTHjU9Mn/2wyAU=
gg-scm.io/pkg/ghdevice v0.1.0/go.mod h1:Cm60XpVqtWmOy5W109MLJ9KBlw25oHEliw/9ivICTQA=
gg-scm.io/pkg/git v0.7.2 h1:8VLpR4ime1q9ziOE3yH3sAOqYHHrXLe+jARoFBv7U6Y=
gg-scm.io/pkg/git v0.7.2/go.mod h1:sjr2w1P0YOu6j4zPeeMA4/brkaBZyGyN+ROlcWMiTO0=
gg-scm.io/pkg/git v0.7.3 h1:O3AH0uUcMYO2924xSe2rDIuIJs4HPk7vZm+c38LiGL0=
gg-scm.io/pkg/git v0.7.3/go.mod h1:sjr2w1P0YOu6j4zPeeMA4/brkaBZyGyN+ROlcWMiTO0=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down

0 comments on commit 1e8c13b

Please sign in to comment.