Skip to content

Instantly share code, notes, and snippets.

@jw3126
Created April 27, 2019 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jw3126/6d2129f9bac5b0b7dce3a160129e1c9c to your computer and use it in GitHub Desktop.
Save jw3126/6d2129f9bac5b0b7dce3a160129e1c9c to your computer and use it in GitHub Desktop.
LibGit2
using LibGit2
repo_path = "LibGit2TestRepo"
repo_url = "git@github.com: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