6
6
# distribution, for details about the copyright.
7
7
#
8
8
9
- import std/ [os, files, dirs, paths, osproc, sequtils, strutils, uri, sets]
9
+ import std/ [os, files, dirs, paths, osproc, options, sequtils, strutils, uri, sets]
10
10
import reporters, osutils, versions, context
11
11
12
12
type
15
15
GitRemoteUrl = " git -C $DIR config --get remote.origin.url" ,
16
16
GitDiff = " git -C $DIR diff" ,
17
17
GitFetch = " git -C $DIR fetch" ,
18
+ GitFetchAll = " git -C $DIR fetch origin " & quoteShell (" refs/heads/*:refs/heads/*" ) & " " & quoteShell (" refs/tags/*:refs/tags/*" ),
18
19
GitTag = " git -C $DIR tag" ,
19
20
GitTags = " git -C $DIR show-ref --tags" ,
20
21
GitLastTaggedRef = " git -C $DIR rev-list --tags --max-count=1" ,
29
30
GitLsFiles = " git -C $DIR ls-files"
30
31
GitLog = " git -C $DIR log --format=%H origin/HEAD"
31
32
GitLogLocal = " git -C $DIR log --format=%H HEAD"
32
- GitCurrentBranch = " git rev-parse --abbrev-ref HEAD"
33
+ GitCurrentBranch = " git -C $DIR rev-parse --abbrev-ref HEAD"
33
34
GitLsRemote = " git -C $DIR ls-remote --quiet --tags"
34
35
GitShowFiles = " git -C $DIR show"
35
36
GitListFiles = " git -C $DIR ls-tree --name-only -r"
@@ -193,9 +194,9 @@ proc shortToCommit*(path: Path, short: CommitHash): CommitHash =
193
194
if vtags.len () == 1 :
194
195
result = vtags[0 ].c
195
196
196
- proc expandSpecial * (path: Path , vtag: VersionTag , errorReportLevel: MsgKind = Warning , isLocalOnly = false ): VersionTag =
197
+ proc expandSpecial * (path: Path , vtag: VersionTag , errorReportLevel: MsgKind = Warning ): VersionTag =
197
198
if vtag.version.isHead ():
198
- return findOriginTip (path, errorReportLevel, isLocalOnly )
199
+ return findOriginTip (path, errorReportLevel, false )
199
200
200
201
let (cc, status) = exec (GitRevParse , path, [vtag.version.string .substr (1 )], errorReportLevel)
201
202
@@ -368,13 +369,6 @@ proc incrementLastTag*(path: Path, field: Natural): string =
368
369
proc isShortCommitHash * (commit: string ): bool {.inline .} =
369
370
commit.len >= 4 and commit.len < 40
370
371
371
- proc updateRepo * (path: Path ) =
372
- let (outp, status) = exec (GitFetch , path, [" --tags" ])
373
- if status != RES_OK :
374
- error (path, " could not update repo: " & outp)
375
- else :
376
- info (path, " successfully updated repo" )
377
-
378
372
proc getRemoteUrl * (path: Path ): string =
379
373
let (cc, status) = exec (GitRemoteUrl , path, [])
380
374
if status != RES_OK :
@@ -383,9 +377,10 @@ proc getRemoteUrl*(path: Path): string =
383
377
else :
384
378
return cc.strip ()
385
379
386
- proc isOutdated * (path: Path ): bool =
380
+ proc hasNewTags * (path: Path ): Option [ tuple [outdated: bool , newTags: int ]] =
387
381
# # determine if the given git repo `f` is updateable
388
- # #
382
+ # # returns an option tuple with the outdated flag and the number of new tags
383
+ # # the option is none if the repo doesn't have remote url or remote tags
389
384
390
385
info path, " checking is package is up to date..."
391
386
@@ -394,33 +389,36 @@ proc isOutdated*(path: Path): bool =
394
389
395
390
let url = getRemoteUrl (path)
396
391
if url.len == 0 :
397
- return false
392
+ return none ( tuple [outdated: bool , newTags: int ])
398
393
let (remoteTagsList, lsStatus) = listRemoteTags (path, url)
399
394
let remoteTags = remoteTagsList.toHashSet ()
400
395
401
396
if not lsStatus:
402
397
warn path, " git list remote tags failed, skipping"
403
- return false
398
+ return none ( tuple [outdated: bool , newTags: int ])
404
399
405
400
if remoteTags > localTags:
406
401
warn path, " got new versions:" , $ (remoteTags - localTags)
407
- return true
402
+ return some ((true , remoteTags.len () - localTags.len ()))
403
+ elif remoteTags.len () == 0 :
404
+ info path, " no local tags found, checking for new commits"
405
+ return none (tuple [outdated: bool , newTags: int ])
408
406
409
- return false
407
+ return some (( false , 0 ))
410
408
411
- proc updateDir * (path: Path , filter: string ) =
412
- let (remote, _) = osproc.execCmdEx (" git remote -v" )
413
- if filter.len == 0 or filter in remote:
414
- let diff = checkGitDiffStatus (path)
415
- if diff.len > 0 :
416
- warn ($ path, " has uncommitted changes; skipped" )
409
+ proc updateRepo * (path: Path , onlyTags = false ) =
410
+ # # updates the repo by
411
+ let url = getRemoteUrl (path)
412
+ if url.len == 0 :
413
+ info path, " no remote URL found; cannot update"
414
+ return
415
+
416
+ let (outp, status) =
417
+ if onlyTags:
418
+ exec (GitFetch , path, [" --tags" , " origin" ])
417
419
else :
418
- let (branch, _) = exec (GitCurrentBranch , path, [])
419
- if branch.strip.len > 0 :
420
- let (output, exitCode) = osproc.execCmdEx (" git pull origin " & branch.strip)
421
- if exitCode != 0 :
422
- error $ path, output
423
- else :
424
- info ($ path, " successfully updated" )
425
- else :
426
- error $ path, " could not fetch current branch name"
420
+ exec (GitFetchAll , path, [])
421
+ if status != RES_OK :
422
+ error (path, " could not update repo: " & outp)
423
+ else :
424
+ notice (path, " successfully updated repo" )
0 commit comments