<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sect1 SYSTEM "../../../dtd/dblite.dtd">
<sect1 id="tsvn-dug-patch">
	<title>Creating and Applying Patches</title>
	<indexterm>
		<primary>patch</primary>
	</indexterm>
	<indexterm>
		<primary>diff</primary>
	</indexterm>
	<indexterm>
		<primary>unified diff</primary>
	</indexterm>
	<?dbhh topicname="HIDD_FORMAT_PATCH"?>
	<?dbhh topicname="HIDD_APPLY_PATCH_LIST"?>
	<?dbhh topicname="HIDD_CREATEPATCH"?>
	<para>
		For open source projects (like this one) everyone has read
		access to the repository, and anyone can make a contribution
		to the project. So how are those contributions controlled?
		If just anyone could commit changes, the project would be permanently
		unstable and probably permanently broken. In this situation the
		change is managed by submitting a <firstterm>patch</firstterm> file
		to the development team, who do have write access.
		They can review the patch first, and then either submit it to the
		repository or reject it back to the author.
	</para>
	<para>
		Patch files are simply Unified-Diff files showing the differences
		between your working copy and the base revision.
	</para>
	<sect2 id="tsvn-dug-patch-1">
		<title>Creating a Patch File</title>
		<para>
			First you need to make <emphasis>and test</emphasis> your changes.
			Then instead of using
			<menuchoice>
				<guimenu>TortoiseGit</guimenu>
				<guimenuitem>Commit...</guimenuitem>
			</menuchoice>
			on the parent folder, you select
			<menuchoice>
				<guimenu>TortoiseGit</guimenu>
				<guimenuitem>Create Patch Serial...</guimenuitem>
			</menuchoice>
		</para>
		<figure id="tsvn-dug-patch-dia-1">
			<title>The Create Patch dialog</title>
			<graphic fileref="../images/CreatePatch.png"/>
		</figure>
		<para>
			<guilabel>Directory</guilabel> is output directory of patch.
			Patch file name will be created by commit subject. 
		</para>
		<para>
			<guilabel>Since</guilabel> create patch from point. You can click
			<guibutton>...</guibutton> to launch refbrowse dialog to choose branch or tag.
		</para>
		<para>
			<guilabel>Number Commits</guilabel> is limited how much patch will created.
		</para>
		<para>
			<guilabel>Range</guilabel> is choose range of <guilabel>from</guilabel> commit 
			to <guilabel>to</guilabel>. You can click <guibutton>...</guibutton> to launch
			log dialog to choose commit.
		</para>
		<para>
			<guilabel>Send Mail after create</guilabel> launch send mail dialog after patches created.
		</para>
	</sect2>
	<sect2 id="tsvn-dug-patch-2">
		<title>Applying a Patch File</title>
		<para>
			Patch files are applied to your working copy. This should be done
			from the same folder level as was used to create the patch.
			If you are not sure what this is, just look at the first line of
			the patch file. For example, if the first file being worked on was
			<filename>doc/source/english/chapter1.xml</filename>
			and the first line in the patch file is
			<filename>Index: english/chapter1.xml</filename>
			then you need to apply the patch to the
			<filename>doc/source/</filename> folder.
			However, provided you are in the correct working copy, if you
			pick the wrong folder level, TortoiseGit will notice and suggest the
			correct level.
		</para>
		<!--
		<para>
			In order to apply a patch file to your working copy, you need
			to have at least read access to the repository.
			The reason for this is that the merge program must
			reference the changes back to the revision against
			which they were made by the remote developer.
		</para>
		-->
		<para>
			From the context menu for that folder, click on
			<menuchoice>
				<guimenu>TortoiseGit</guimenu>
				<guimenuitem>Apply Patch Serial...</guimenuitem>
			</menuchoice>
			<figure id="tsvn-dug-apply-patch">
				<title>The Apply Patch Dialog</title>
				<graphic fileref="../images/ApplyPatch.png"/>
			</figure>
		</para>
		<para>
			Alternatively, if the patch file has a <filename>.patch</filename>
			or <filename>.diff</filename> extension, you can right click on it
			directly and select
			<menuchoice>
				<guimenu>TortoiseGit</guimenu>
				<guimenuitem>Apply Patch...</guimenuitem>
			</menuchoice>.
			In this case you will be prompted to enter a working copy location.
			<figure id="tsvn-dug-choose-repository">
				<title>The Choose Repository Dialog</title>
				<graphic fileref="../images/ChooseRepository.png"/>
			</figure>
		</para>
		<para>
			<guibutton>Add</guibutton> insert patch
		</para>
		<para>
			<guibutton>Up</guibutton> Move chosen patch up.
		</para>
		<para>
			<guibutton>Down</guibutton> Move Chosen patch down.
		</para>
		<para>
			<guibutton>Remove</guibutton> Remove Chosen patch.
		</para>
		<para>
			<guibutton>Apply</guibutton> start apply patch one by one
		</para>
	</sect2>
</sect1>
