Created
April 27, 2019 14:46
-
-
Save jw3126/6d2129f9bac5b0b7dce3a160129e1c9c to your computer and use it in GitHub Desktop.
LibGit2
This file contains hidden or 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
using LibGit2 | |
repo_path = "LibGit2TestRepo" | |
repo_url = "[email protected]:jw3126/LibGit2TestRepo.git" | |
rm(repo_path, recursive=true, force=true) | |
mkpath(path) | |
# init | |
repo = try | |
@info "Cloning repo" | |
LibGit2.clone(repo_url, repo_path, ) | |
catch err | |
@error err | |
@info "cannot clone from $repo_url init new repo" | |
origin = LibGit2.GitRemote(repo, "origin", repo_url) | |
LibGit2.init(repo_path) | |
end | |
# commit | |
filename = "file1.txt" | |
filepath = joinpath(repo_path, filename) | |
write(filepath, "1") | |
LibGit2.add!(repo, filename) | |
LibGit2.commit(repo, "commit1") | |
# check repo clean and tidy | |
@assert !LibGit2.isdirty(repo) | |
@assert LibGit2.branch(repo) == "master" | |
# push | |
LibGit2.push(repo, force=true, remote="origin", refspecs=["refs/heads/master"]) | |
# tagging | |
tl = LibGit2.tag_list(repo) | |
ts = map(tl) do t | |
parse(Int, t) | |
end | |
n = reduce(max, ts, init=0) + 1 | |
LibGit2.tag_create(repo, string(n), "master") | |
LibGit2.push(repo, force=true, remote="origin", refspecs=["refs/tags/$n"]) | |
@show LibGit2.tag_list(repo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment