diff src/org/tmatesoft/hg/core/HgCheckoutCommand.java @ 527:47b7bedf0569

Tests for present HgCheckoutCommand functionality. Update branch information on checkout. Use UTF8 encoding for the branch file
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 15 Jan 2013 19:46:19 +0100
parents 2f9ed6bcefa2
children ca56a36c2eea
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/core/HgCheckoutCommand.java	Tue Jan 15 17:07:19 2013 +0100
+++ b/src/org/tmatesoft/hg/core/HgCheckoutCommand.java	Tue Jan 15 19:46:19 2013 +0100
@@ -16,14 +16,17 @@
  */
 package org.tmatesoft.hg.core;
 
+import static org.tmatesoft.hg.repo.HgRepositoryFiles.Branch;
 import static org.tmatesoft.hg.repo.HgRepositoryFiles.Dirstate;
 
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 import java.nio.channels.FileChannel;
 
 import org.tmatesoft.hg.internal.DirstateBuilder;
+import org.tmatesoft.hg.internal.EncodingHelper;
 import org.tmatesoft.hg.internal.Experimental;
 import org.tmatesoft.hg.internal.Internals;
 import org.tmatesoft.hg.internal.WorkingDirFileWriter;
@@ -130,7 +133,19 @@
 			} catch (IOException ex) {
 				throw new HgIOException("Can't write down new directory state", ex, dirstateFile);
 			}
-			// FIXME write down branch file
+			String branchName = repo.getChangelog().range(revisionToCheckout, revisionToCheckout).get(0).branch();
+			assert branchName != null;
+			if (!HgRepository.DEFAULT_BRANCH_NAME.equals(branchName)) {
+				File branchFile = internalRepo.getRepositoryFile(Branch);
+				try {
+					// branch file is UTF-8, see http://mercurial.selenic.com/wiki/EncodingStrategy#UTF-8_strings
+					OutputStreamWriter ow = new OutputStreamWriter(new FileOutputStream(branchFile), EncodingHelper.getUTF8());
+					ow.write(branchName);
+					ow.close();
+				} catch (IOException ex) {
+					throw new HgIOException("Can't write down branch information", ex, branchFile);
+				}
+			}
 		} catch (HgRuntimeException ex) {
 			throw new HgLibraryFailureException(ex);
 		}