|
1
|
# The "fossil patch" command |
|
2
|
|
|
3
|
The "[fossil patch](/help/patch)" command is designed to transfer |
|
4
|
uncommitted changes from one check-out to another, including transfering |
|
5
|
those changes to other machines. |
|
6
|
|
|
7
|
For example, if you are working on a Windows desktop and you want to |
|
8
|
test your changes on a Linux server before you commit, you can use the |
|
9
|
"fossil patch push" command to make a copy of all your changes on the |
|
10
|
remote Linux server: |
|
11
|
|
|
12
|
fossil patch push linuxserver:/path/to/checkout |
|
13
|
|
|
14
|
In the previous line "linuxserver" is the name of the remote machine and |
|
15
|
"/path/to/checkout" is an existing checkout directory for the same project |
|
16
|
on the remote machine. |
|
17
|
|
|
18
|
The "fossil patch push" command works by first creating a patch file, |
|
19
|
then transfering that patch file to the remote machine using "ssh", then |
|
20
|
applying the patch. If you do not have ssh available, you can break these |
|
21
|
steps apart as follows: |
|
22
|
|
|
23
|
1. On the local machine: `fossil patch create mypatch.patch` |
|
24
|
2. Move "mypatch.patch" to the remote machine. |
|
25
|
3. On the remote machine: `fossil patch apply mypatch.patch` |
|
26
|
|
|
27
|
Step 2 can be accomplished by a variety of means including |
|
28
|
posting the mypatch.patch file on [chat](./chat.md) or sending |
|
29
|
it as an email attachment. |
|
30
|
|
|
31
|
## Setup |
|
32
|
|
|
33
|
The "fossil patch push" and "fossil patch pull" commands will only work if you have |
|
34
|
"ssh" available on the local machine and if "fossil" is on the default |
|
35
|
PATH on the remote machine. |
|
36
|
|
|
37
|
To check if Fossil is installed correctly on the remote, try a command |
|
38
|
like this: |
|
39
|
|
|
40
|
ssh -T remote "fossil version" |
|
41
|
|
|
42
|
If the command above shows a recent version of Fossil, then you should be |
|
43
|
set to go. If you get "fossil not found", or if the version shown is too |
|
44
|
old, put a newer fossil executable on the default PATH. The default PATH |
|
45
|
can be shown using: |
|
46
|
|
|
47
|
ssh -T remote 'echo $PATH' |
|
48
|
|
|
49
|
### Custom PATH Caveat |
|
50
|
|
|
51
|
On Unix-like systems, the init script for the user's login shell |
|
52
|
(e.g. `~/.profile` or `~/.bash_profile`) may be configured to *not do |
|
53
|
anything* when running under a non-interactive shell. Thus a fossil |
|
54
|
binary installed to a custom directory might not be found. To allow |
|
55
|
the patch command to use a fossil binary installed in a directory |
|
56
|
which is normally added to the PATH via the interactive shell's init |
|
57
|
script, it may be useful to disable that check. For example, |
|
58
|
Ubuntu-derived systems sometimes start their default `.bashrc` with |
|
59
|
something like: |
|
60
|
|
|
61
|
``` |
|
62
|
# If not running interactively, don't do anything: |
|
63
|
[ -z "$PS1" ] && return |
|
64
|
# Or: |
|
65
|
case $- in |
|
66
|
*i*) ;; |
|
67
|
*) return;; |
|
68
|
esac |
|
69
|
``` |
|
70
|
|
|
71
|
Commenting out that check will allow the patch command to run, for |
|
72
|
example, `~/bin/fossil` if `~/bin` is added to the PATH via the init |
|
73
|
script. To disable that check *only* when the shell is *not* running |
|
74
|
over an SSH connection, something like the following should suffice: |
|
75
|
|
|
76
|
``` |
|
77
|
if [ -z "$SSH_CONNECTION" ]; then |
|
78
|
# ... the is-interactive check goes here ... |
|
79
|
fi |
|
80
|
``` |
|
81
|
|
|
82
|
|
|
83
|
## Implementation Details |
|
84
|
|
|
85
|
The "fossil patch create" command records all of the local, uncommitted |
|
86
|
changes in an SQLite database file. If the argument to "fossil patch create" |
|
87
|
is a filename, then the patch-file database is written into that file. |
|
88
|
If the argument is "-" then the database is written on standard output. |
|
89
|
|
|
90
|
The "fossil patch apply" command reads the patch-file database |
|
91
|
and applies it to the local check-out. If a filename is given as an |
|
92
|
argument, then the database is read from that file. If the argument is "-" |
|
93
|
then the database is read from standard input. |
|
94
|
|
|
95
|
Hence the command: |
|
96
|
|
|
97
|
fossil patch push remote:projectA |
|
98
|
|
|
99
|
Is equivalent to: |
|
100
|
|
|
101
|
fossil patch create - | ssh -T remote 'cd projectA;fossil patch apply -' |
|
102
|
|
|
103
|
Likewise, a command like this: |
|
104
|
|
|
105
|
fossil patch pull remote:projB |
|
106
|
|
|
107
|
could be entered like this: |
|
108
|
|
|
109
|
ssh -T remote 'cd projB;fossil patch create -' | fossil patch apply - |
|
110
|
|
|
111
|
The "fossil patch view" command just opens the patch-file database and prints |
|
112
|
a summary of its contents on standard output. |
|
113
|
|