-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pull or fetch available? #20
Comments
It's missing from upstream, or was. I haven't checked recently. Once libgit2 has it, it's easy for us to add it. |
oh I see - it is missing even further upstream in libgit2.. |
Yeah, I'd really like to have shallow checkout also. 😞 |
@disruptek I looked through some non-nim libs binding gitlib2. @disruptek , @haxscramper in the case of gittyup, would you see pull in hlibgit2 or in gittyup? |
hlibgit2 is a 1:1 mapping of the C library, so it is only concerned with wrapping the code that is already present in the libgit2 API. Gittyup, on the other hand, is a lot better place for this sort of improvements and I don't see any reason why missing functionality could not be added. |
@haxscramper : thank you for the quick response - sounds good to me. 🙂 |
If you produce a PR, I will be happy to merge it. We can refine it from there; it's new API, so it doesn't really matter how well it works, though the tests are far more important than the implementation. The more trivial |
I think as start, I would first post the snippet here - |
import os
import nimgit2
import strformat
import strutils
type
Repo = git_repository
GitOId = git_oid
GitTime = git_time_t
StrArray = git_strarray
GitReference = git_reference
Commit = git_commit
func `$`*(oid: var GitOId): string =
result = $git_oid_tostr_s(addr oid)
proc info(text: string) {.discardable.} =
echo "[INFO] ", text
proc error(text: string) {.discardable.} =
echo "[ERROR] ", text
proc reportResult(resultCode: int, resultName: string) {.discardable.} =
if resultCode < 0:
let lastErr = git_error_last()
($(lastErr.klass) & ": " & $(lastErr.message)).error
else:
# "success: {resultName}: {resultCode}".info
return
proc getOidFromSha(sha: cstring): GitOId =
reportResult(git_oid_fromstr(addr result, sha), "getOidFromSha")
proc getShaFromOid(oid: var GitOId): cstring =
return git_oid_tostr_s(addr oid)
proc getCommitFromSha(repo: ptr Repo, sha: cstring): ptr Commit =
var
shaOid = getOidFromSha(sha)
shaCommit: ptr git_commit
let commitFromShaResult = git_commit_lookup(addr shaCommit, repo, addr shaOid)
reportResult(commitFromShaResult, "commitFromShaResult")
return shaCommit
proc report_merge_analysis(result: git_merge_analysis_t) =
if result == GIT_MERGE_ANALYSIS_NONE: fmt"GIT_MERGE_ANALYSIS_NONE : {GIT_MERGE_ANALYSIS_NONE}" .info
elif result == GIT_MERGE_ANALYSIS_NORMAL: fmt"GIT_MERGE_ANALYSIS_NORMAL : {GIT_MERGE_ANALYSIS_NORMAL}" .info
elif result == GIT_MERGE_ANALYSIS_UP_TO_DATE: fmt"GIT_MERGE_ANALYSIS_UP_TO_DATE : {GIT_MERGE_ANALYSIS_UP_TO_DATE}" .info
elif result == GIT_MERGE_ANALYSIS_FASTFORWARD: fmt"GIT_MERGE_ANALYSIS_FASTFORWARD: {GIT_MERGE_ANALYSIS_FASTFORWARD}".info
elif result == GIT_MERGE_ANALYSIS_UNBORN: fmt"GIT_MERGE_ANALYSIS_UNBORN : {GIT_MERGE_ANALYSIS_NONE}" .info
fmt"GIT_MERGE_ANALYSIS: {result}".info
const
repoPath = "/tmp/gittyup"
branchName = "master"
remoteName = "origin"
url = "https://github.com/disruptek/gittyup"
masterRef = "refs/remotes/origin/master"
logMessage = "attempt to fetch / pull fast forward"
refLogMessage = "fetch"
theirHeadsLen = 1.cuint
let initResult = git_libgit2_init()
reportResult(initResult, "init_result")
var
repo: ptr Repo
repoHeadRef: ptr GitReference
fetchOpts: git_fetch_options
remote: ptr git_remote
refSpecs: StrArray
gitRef: ptr GitReference
fetchAnnoCommit: ptr git_annotated_commit
checkoutOpt: git_checkout_options
mergeAnalysis: git_merge_analysis_t
mergePreference: git_merge_preference_t
newTargetRef: ptr GitReference
fmt"clone or pull of {url} at {repoPath}".info
if not repoPath.dir_exists():
"repo does not exist yet: cloning..".info
let cloneOpenResult = git_clone(addr repo, url, repoPath, nil)
reportResult(cloneOpenResult, "cloneOpenResult")
else:
"repo exists: opening..".info
let openResult = git_repository_open(addr repo, repoPath)
reportResult(openResult, "openResult")
let repoHeadRefResult = git_repository_head(addr repoHeadRef, repo)
reportResult(repoHeadRefResult, "repoHeadRefResult")
"fetching..".info
let optInitResult = git_fetch_options_init(addr fetchOpts, 1.cuint)
reportResult(optInitResult, "optInitResult")
let remoteResult = git_remote_lookup(addr remote, repo, remoteName)
reportResult(remoteResult, "remoteResult")
let fetchResult = git_remote_fetch(remote, addr refSpecs, addr fetchOpts, refLogMessage)
reportResult(fetchResult, "fetchResult")
let remoteMasterIdResult = git_reference_lookup(addr gitRef, repo, masterRef)
reportResult(remoteMasterIdResult, "remoteMasterIdResult")
let refTarget = git_reference_target(git_ref)
let fetchAnnoRes = git_annotated_commit_from_fetchhead(addr fetchAnnoCommit,
repo, branchName, url, refTarget)
reportResult(fetchAnnoRes, "fetchAnnoRes")
let analyseResult = git_merge_analysis(addr mergeAnalysis, addr mergePreference,
repo, addr fetchAnnoCommit, theirHeadsLen)
reportResult(analyseResult, "analyseResult")
reportMergeAnalysis(mergeAnalysis)
if mergeAnalysis == GIT_MERGE_ANALYSIS_UP_TO_DATE:
"nothing to do: UP_TO_DATE".info
elif mergeAnalysis == GIT_MERGE_ANALYSIS_FASTFORWARD:
"WIP: GIT_MERGE_ANALYSIS_FASTFORWARD".info
elif mergeAnalysis == 5:
"WIP: GIT_MERGE_ANALYSIS: NORMAL & FASTFORWARD".info
var optRes = git_checkout_options_init(addr checkoutOpt, GIT_CHECKOUT_OPTIONS_VERSION)
reportResult(optRes, "optRes")
let remoteMasterId = getShaFromOid(ref_target[])
fmt"{remoteMasterId =}".info
let
remoteMasterCommit = getCommitFromSha(repo, remoteMasterId)
commitToObj = cast[ptr git_object](remoteMasterCommit)
checkoutResult = git_checkout_tree(repo, commitToObj, addr checkoutOpt)
reportResult(checkoutResult, "checkoutResult")
let setTargetRes = git_reference_set_target(addr newTargetRef, repoHeadRef,
refTarget, logMessage)
reportResult(setTargetRes, "setTargetRes")
elif mergeAnalysis == GIT_MERGE_ANALYSIS_NORMAL:
"WIP: GIT_MERGE_ANALYSIS_NORMAL".info
else:
"WIP: other GIT_MERGE_ANALYSIS".info
let shutdownResult = git_libgit2_shutdown()
fmt"{shutdownResult =}".info ^^ this is the snippet @fbpyr mentioned. |
thank you @fbe-work - exactly. 🙂 |
Holy shit, someone is actually using |
@disruptek trying my first gittyup fetch test, I am wondering (sorry potentially noob question): |
You could use Nimph or Nimble with local dependencies mode, right? With Nimph, |
that sounds ery useful! will try. thank you so much! |
maybe a duplicate of #5 (?)
or maybe I have overlooked something,
but I did not find a way to
pull
l orfetch
in gittyup or hlibgit2.does it exist, or are there plans to support it?
or is it blocked somewhere upstream?
thank you. 🙂
The text was updated successfully, but these errors were encountered: