Skip to content

Commit 65b7313

Browse files
(#1) Added instructions on moving code from other repos (#4)
* (#1) Added instructions on moving code from other repos * (#1) Use a nicer filtering tool for hisotries * Move how-to for moving code from README to docs/developer/how-to/move-code --------- Co-authored-by: Noemi Frisina <noemi.frisina@diamond.ac.uk>
1 parent 68738fc commit 65b7313

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
python-dodal
2-
===========================
2+
============
33

44
|code_ci| |docs_ci| |coverage| |pypi_version| |license|
55

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
Moving code from another repo
3+
=============================
4+
5+
In the process of writing code in other DLS repos you may come to realise that it makes more sense to be in ``dodal``. It is a good idea to keep the history for this code, you can do this by doing the following (we will be using moving devices from https://github.com/DiamondLightSource/python-artemis as an example):
6+
7+
#. Clone the codebase you are copying from::
8+
9+
git clone git@github.com:DiamondLightSource/python-artemis.git clone_for_history
10+
cd clone_for_history/
11+
12+
#. Remove the remote to avoid any mistaken pushes::
13+
14+
git remote rm origin
15+
16+
#. Filter out only the directory/file you want to move::
17+
18+
pip install git-filter-repo
19+
git-filter-repo --path file/to/move --path /other/file/to/move -f
20+
21+
#. Clean everything up::
22+
23+
git reset --hard
24+
git gc --aggressive
25+
git prune
26+
git clean -fd
27+
28+
#. Add a note to every commit message to mention it's been moved::
29+
30+
git filter-branch --msg-filter 'sed "$ a \
31+
NOTE: Commit originally came from https://github.com/DiamondLightSource/python-artemis"' -f -- --all
32+
33+
#. If you have been using Github `issue references`_ in the old repository modify these to point to be more explicit (Note that this assumes the old repo uses ``#123`` notation and only ever references issues from it's own repo)::
34+
35+
git filter-branch -f --msg-filter 'sed "s|#[0-9]\+|DiamondLightSource/python-artemis&|g"' -- --all
36+
37+
#. Prepare the code to be in the correct structure for dodal::
38+
39+
mkdir -p src/dodal/devices
40+
mv path/to/device src/dodal/devices/
41+
42+
#. At this point it's a good idea to check the log ``git log`` and the general directory structure to ensure it looks mostly correct
43+
44+
#. Add and commit this (locally)::
45+
46+
git add .
47+
git commit -m "Prepare for import into dodal"
48+
49+
#. In a different folder clone ``dodal``, remove the origin (for now) to be safe and create a branch::
50+
51+
git clone git@github.com:DiamondLightSource/python-dodal.git
52+
cd dodal
53+
git remote rm origin
54+
git checkout -b add_code_from_artemis
55+
56+
#. Add the source repo as a remote for ``dodal``::
57+
58+
git remote add source /path/to/source/old_repo/.git
59+
60+
#. Pull from the source repo::
61+
62+
git pull --no-rebase source main --allow-unrelated-histories
63+
64+
#. This is another point where it's a good idea to check the log ``git log`` and the general directory structure to ensure it looks mostly correct
65+
66+
#. Remove the source remote and re-add origin::
67+
68+
git remote rm source
69+
git remote add origin git@github.com:DiamondLightSource/python-dodal.git
70+
71+
#. Tidy up the code so that it fits into the ``dodal`` repo e.g. in the Artemis case we had to change the tests to import from ``artemis`` to import from ``dodal`` and add some more dependencies.
72+
73+
.. _issue references: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/autolinked-references-and-urls#issues-and-pull-requests

docs/developer/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ side-bar.
2626
:maxdepth: 1
2727

2828
how-to/contribute
29+
how-to/move-code
2930
how-to/build-docs
3031
how-to/run-tests
3132
how-to/static-analysis

0 commit comments

Comments
 (0)