-
-
Save dhoizner/c30782a4d93e634d84be4cc10fee38ed to your computer and use it in GitHub Desktop.
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
testing on 🌱 main +/- [⇣] | |
❯ grhh origin/main | |
HEAD is now at d12b384 update hello.txt | |
testing on 🌱 main +/- | |
❯ echo 'abc'>>hello.txt && gaa && gcmsg 'update hello.txt' && ggpush | |
[main a8c4ef6] update hello.txt | |
1 file changed, 1 insertion(+) | |
Enumerating objects: 5, done. | |
Counting objects: 100% (5/5), done. | |
Writing objects: 100% (3/3), 256 bytes | 256.00 KiB/s, done. | |
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 | |
To github.com:dhoizner/testing.git | |
d12b384..a8c4ef6 main -> main | |
testing on 🌱 main +/- | |
❯ echo 'abc'>>hello.txt && gaa && gcmsg 'update hello.txt' && ggpush | |
[main 40a6225] update hello.txt | |
1 file changed, 1 insertion(+) | |
Enumerating objects: 5, done. | |
Counting objects: 100% (5/5), done. | |
Writing objects: 100% (3/3), 256 bytes | 256.00 KiB/s, done. | |
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 | |
To github.com:dhoizner/testing.git | |
a8c4ef6..40a6225 main -> main | |
testing on 🌱 main +/- | |
❯ echo 'abc'>>hello.txt && gaa && gcmsg 'update hello.txt' && ggpush | |
[main 70ea39b] update hello.txt | |
1 file changed, 1 insertion(+) | |
Enumerating objects: 5, done. | |
Counting objects: 100% (5/5), done. | |
Writing objects: 100% (3/3), 255 bytes | 255.00 KiB/s, done. | |
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 | |
To github.com:dhoizner/testing.git | |
40a6225..70ea39b main -> main | |
testing on 🌱 main +/- | |
❯ |
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
~/workspace/fun-with-go-git via 🐹 v1.21.1 took 1m52s | |
❯ go run main.go | |
cloned | |
head: d12b38413440bcc718c590135175a3630f423a58 | |
newline to pull, exit to exit | |
> | |
pulling | |
head: a8c4ef6470f6f7b4cd2efecb6dd4337f71893d43 | |
newline to pull, exit to exit | |
> | |
pulling | |
head: a8c4ef6470f6f7b4cd2efecb6dd4337f71893d43 | |
newline to pull, exit to exit | |
> | |
pulling | |
head: 70ea39ba35e16947e002c5c077e5985383000f5d | |
newline to pull, exit to exit | |
> |
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
package main | |
import ( | |
"bufio" | |
"context" | |
"fmt" | |
"os" | |
"os/signal" | |
"github.com/go-git/go-git/v5" | |
"github.com/go-git/go-git/v5/plumbing/transport/ssh" | |
ssh2 "golang.org/x/crypto/ssh" | |
) | |
func main() { | |
if stat, err := os.Stat("./repos/testing"); err == nil && stat.IsDir() { | |
if err := os.RemoveAll("./repos/testing"); err != nil { | |
panic(err) | |
} | |
} | |
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) | |
defer stop() | |
keys, err := ssh.NewPublicKeysFromFile("git", "/Users/dan.hoizner/.ssh/id_ed25519", "") | |
if err != nil { | |
panic(err) | |
} | |
keys.HostKeyCallback = ssh2.InsecureIgnoreHostKey() | |
repo, err := git.PlainCloneContext(ctx, "./repos/testing", false, &git.CloneOptions{ | |
URL: "github.com:dhoizner/testing.git", | |
SingleBranch: true, | |
ReferenceName: "refs/heads/main", | |
Auth: keys, | |
Depth: 1, | |
}) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println("cloned") | |
head, err := repo.Head() | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println("head: ", head.Hash()) | |
reader := bufio.NewReader(os.Stdin) | |
for { | |
fmt.Printf("newline to pull, exit to exit\n> ") | |
// in the meantime commit and push to the repo so there's smth to pull | |
line, _, err := reader.ReadLine() | |
if err != nil { | |
panic(err) | |
} | |
if string(line) == "exit" { | |
return | |
} | |
tree, err := repo.Worktree() | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println("pulling") | |
if err = tree.PullContext(ctx, &git.PullOptions{ | |
Auth: keys, | |
// Depth: 100000, | |
SingleBranch: true, | |
ReferenceName: "refs/heads/main", | |
Force: true, | |
}); err != nil { | |
panic(err) | |
} | |
head, err := repo.Head() | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println("head: ", head.Hash()) | |
} | |
} |
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
module fun-with-go-git | |
go 1.21.1 | |
require ( | |
github.com/go-git/go-git/v5 v5.10.1-0.20231127160659-861009f70a5b | |
golang.org/x/crypto v0.16.0 | |
) | |
require ( | |
dario.cat/mergo v1.0.0 // indirect | |
github.com/Microsoft/go-winio v0.6.1 // indirect | |
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect | |
github.com/cloudflare/circl v1.3.3 // indirect | |
github.com/cyphar/filepath-securejoin v0.2.4 // indirect | |
github.com/emirpasic/gods v1.18.1 // indirect | |
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect | |
github.com/go-git/go-billy/v5 v5.5.0 // indirect | |
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect | |
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect | |
github.com/kevinburke/ssh_config v1.2.0 // indirect | |
github.com/pjbgf/sha1cd v0.3.0 // indirect | |
github.com/sergi/go-diff v1.1.0 // indirect | |
github.com/skeema/knownhosts v1.2.1 // indirect | |
github.com/xanzy/ssh-agent v0.3.3 // indirect | |
golang.org/x/mod v0.12.0 // indirect | |
golang.org/x/net v0.18.0 // indirect | |
golang.org/x/sys v0.15.0 // indirect | |
golang.org/x/tools v0.13.0 // indirect | |
gopkg.in/warnings.v0 v0.1.2 // indirect | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment