mercurial/HGWorkingCopy.st
changeset 152 9068fe7a5795
parent 146 1015b8f6dc1c
child 156 725d8bc65e48
--- a/mercurial/HGWorkingCopy.st	Mon Dec 10 02:49:43 2012 +0000
+++ b/mercurial/HGWorkingCopy.st	Mon Dec 10 03:43:12 2012 +0000
@@ -25,6 +25,38 @@
     "Created: / 27-11-2012 / 13:51:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+branch: aStringOrHGBranch
+    "Set branch for subsequent commits. Returns new branch as HGBranch"
+
+    | name |
+
+    name := aStringOrHGBranch asString.
+
+    self branch name = name ifTrue:[ ^ self ].
+
+    (root asFilename / '.hg' / 'branch') exists ifTrue:[
+        (root asFilename / '.hg' / 'branch') 
+            copyTo: (root asFilename / '.hg' / 'undo.branch')
+    ] ifFalse:[
+        "File DOES contain trailing newline"
+        (root asFilename / '.hg' / 'undo.branch') writingFileDo:[:s|
+            s nextPutLine: 'default'.
+        ]    
+    ].
+    (root asFilename / '.hg' / 'branch') writingFileDo:[:s|
+        s nextPutLine: name.
+    ].
+
+    "Return HGBranch here"
+    ^ aStringOrHGBranch isString ifFalse:[
+        aStringOrHGBranch
+    ] ifTrue:[
+        repository branchWithName: name createIfAbsent: true.
+    ]
+
+    "Created: / 10-12-2012 / 03:04:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 changeset
     "Return an HGChangeset representing the checked-out changeset
      (revision) of the receiver"