mercurial/HGWorkingCopy.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 30 Nov 2012 21:42:46 +0000
changeset 115 b1ed2d29054b
parent 107 c92f7674485e
child 123 ee1cc926f489
permissions -rw-r--r--
version_HG changed to return string. Bu default, there is no real changeset id in the string (unless KeywordsExtension is enabled). However, there is no need for stc itself now embeds changeset id into binary revision.

"{ Package: 'stx:libscm/mercurial' }"

HGRepositoryObject subclass:#HGWorkingCopy
	instanceVariableNames:'root'
	classVariableNames:''
	poolDictionaries:''
	category:'SCM-Mercurial-Core'
!


!HGWorkingCopy methodsFor:'accessing'!

branch
    "Return currently checked-out branch"

    | name |

    name := 'default'.
    (root asFilename / '.hg' / 'branch') exists ifTrue:[
        "File DOES contain trailing newline"    
        name := (root asFilename / '.hg' / 'branch') contents first.
    ].
    ^repository branchWithName: name.

    "Created: / 27-11-2012 / 13:51:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

changeset
    "Return an HGChangeset representing the checked-out changeset
     (revision) of the receiver"

    | id |

    (root asFilename / '.hg' / 'dirstate') readingFileDo:[:s|
        s binary.
        id := HGChangesetId fromBytes: (s next: 20).
    ].

    ^repository changesetWithId: id.

    "Created: / 13-11-2012 / 21:47:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

heads
    "Return heads of currently checked-out branch"

    ^self branch heads

    "Created: / 27-11-2012 / 21:51:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

path
    "Return a path to the root directory of the receiver as *Filename*. 
     Use #root to get the root working copy file"

    ^repository path

    "Created: / 17-10-2012 / 13:53:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

repository
    ^repository

    "Created: / 15-11-2012 / 09:48:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

root
    ^ root
! !

!HGWorkingCopy methodsFor:'actions'!

commit: message
    "Commits all uncommited changes with given message"

    ^self commit: message files: nil

    "Created: / 12-11-2012 / 22:35:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

commit:message files:files 
    "Commit given files with given message. If files
     is nil, all tracked modified files are commited"
    
    ^ (HGCommand commit)
        workingDirectory:root pathName;
        message:message;
        files:files;
        execute

    "Created: / 12-11-2012 / 22:36:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 17-11-2012 / 01:01:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

update: revisionOrBranch

    ^HGCommand update
        workingDirectory: self path;
        revision: revisionOrBranch asString;
        execute

    "Created: / 21-11-2012 / 00:21:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGWorkingCopy methodsFor:'initialization'!

setRepository: aHGRepository
    super setRepository: aHGRepository.
    root :=HGWorkingCopyFile wc: self path: repository path.

    "Created: / 19-09-2012 / 09:43:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 19-10-2012 / 15:44:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGWorkingCopy methodsFor:'inspecting'!

browse
    "Opens a file browser on the working copy"

    root browse

    "Created: / 04-02-2012 / 17:14:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 15-11-2012 / 17:00:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGWorkingCopy methodsFor:'instance creation'!

/ aString
    ^root construct: aString

    "Created: / 24-09-2012 / 13:49:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

construct: aString

    ^root construct: aString

    "Created: / 24-09-2012 / 13:50:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!HGWorkingCopy class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
!

version_SVN
    ^ '§Id::                                                                                                                        §'
! !