Skip to content

Commit f0e724e

Browse files
herbygillotclaude
andcommitted
port: add 'source' subcommand for managing sources.conf
Add `port source` to list, add, and remove entries in sources.conf. `--add` supports `--first` (insert before existing sources, after leading comments) and `--no-sync` (append [nosync] flag). Bare local paths starting with / or ~ are automatically normalized and converted to file:// URLs by both --add and --remove; file:// URLs are validated to ensure the target directory exists. Write operations are atomic (write to temp file, then rename), check for write permission, and emit a sudo hint on failure. Business logic lives in three new procs in macports1.0/macports.tcl: source_normalize_url (shared path expansion and URL validation), source_add, and source_remove. The sources.conf regex is promoted to a namespace variable so it is shared with mportinit. port.tcl contains the thin UI wrapper (action_source). Includes 19 tcltest unit tests (sources.test), a new port-source(1) man page (port-source.1.txt), and updates to port(1). Fixes: https://trac.macports.org/ticket/73683 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8c8e12d commit f0e724e

8 files changed

Lines changed: 1026 additions & 2 deletions

File tree

doc/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ MAN1= \
7878
port-setrequested.1 \
7979
port-setunrequested.1 \
8080
port-snapshot.1 \
81+
port-source.1 \
8182
port-space.1 \
8283
port-sync.1 \
8384
port-test.1 \

doc/port-source.1

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
'\" t
2+
.TH "PORT\-SOURCE" "1" "2\&.12\&.99" "MacPorts 2\&.12\&.99" "MacPorts Manual"
3+
.\" -----------------------------------------------------------------
4+
.\" * Define some portability stuff
5+
.\" -----------------------------------------------------------------
6+
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7+
.\" http://bugs.debian.org/507673
8+
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9+
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10+
.ie \n(.g .ds Aq \(aq
11+
.el .ds Aq '
12+
.\" -----------------------------------------------------------------
13+
.\" * set default formatting
14+
.\" -----------------------------------------------------------------
15+
.\" disable hyphenation
16+
.nh
17+
.\" disable justification (adjust text to left margin only)
18+
.ad l
19+
.\" -----------------------------------------------------------------
20+
.\" * MAIN CONTENT STARTS HERE *
21+
.\" -----------------------------------------------------------------
22+
.SH "NAME"
23+
port-source \- List, add, and remove MacPorts port tree sources
24+
.SH "SYNOPSIS"
25+
.sp
26+
.nf
27+
\fBport\fR [\fB\-dv\fR] \fBsource\fR [\-\-list]
28+
.fi
29+
.sp
30+
.nf
31+
\fBport\fR [\fB\-dv\fR] \fBsudo\fR \fBsource\fR \fB\-\-add\fR [\fB\-\-first\fR] [\fB\-\-no\-sync\fR] \fIurl\fR
32+
.fi
33+
.sp
34+
.nf
35+
\fBport\fR [\fB\-dv\fR] \fBsudo\fR \fBsource\fR \fB\-\-remove\fR \fIurl\fR
36+
.fi
37+
.SH "DESCRIPTION"
38+
.sp
39+
\fBport source\fR manages the list of port tree sources configured in \fBsources.conf\fR(5)\&. Port tree sources tell MacPorts where to find port definitions (Portfiles)\&.
40+
.sp
41+
\fBport source\fR has three modes of operation: listing the currently configured sources, adding a new source, and removing an existing source\&. See \fBOPTIONS\fR below for details\&. Changes made by \fB\-\-add\fR and \fB\-\-remove\fR take effect the next time \fBport\fR is invoked\&.
42+
.sp
43+
A local directory path beginning with \fI/\fR or \fI~\fR is automatically expanded to a \fIfile://\fR URL by both \fB\-\-add\fR and \fB\-\-remove\fR, making it convenient to manage local checkouts of the MacPorts ports tree without needing to type the full \fIfile://\fR URL\&.
44+
.SH "OPTIONS"
45+
.PP
46+
\fB\-\-list\fR
47+
.RS 4
48+
Print the currently configured sources, one per line, in the same format used by
49+
\fBsources.conf\fR(5)\&. This is the default when no option is given\&.
50+
.RE
51+
.PP
52+
\fB\-\-add\fR [\fB\-\-first\fR] [\fB\-\-no\-sync\fR] \fIurl\fR
53+
.RS 4
54+
Add
55+
\fIurl\fR
56+
to the list of port tree sources\&. If
57+
\fIurl\fR
58+
begins with
59+
\fI/\fR
60+
or
61+
\fI~\fR, it is interpreted as a local directory path; it will be normalised and prefixed with
62+
\fIfile://\fR\&.
63+
.sp
64+
By default the new source is appended to the end of
65+
\fBsources.conf\fR(5)\&. Use
66+
\fB\-\-first\fR
67+
to insert it before the first existing source entry, which is useful for a local port tree that should shadow the default remote source\&.
68+
.sp
69+
Use
70+
\fB\-\-no\-sync\fR
71+
to add the
72+
\fI[nosync]\fR
73+
flag to the entry, preventing
74+
\fBport sync\fR
75+
from attempting to update this source\&. This is recommended for local development checkouts that are managed independently\&.
76+
.sp
77+
This command requires write access to
78+
\fBsources.conf\fR(5)
79+
and must typically be run with
80+
\fBsudo\fR\&.
81+
.RE
82+
.PP
83+
\fB\-\-remove\fR \fIurl\fR
84+
.RS 4
85+
Remove the source with the given URL from
86+
\fBsources.conf\fR(5)\&. If
87+
\fIurl\fR
88+
begins with
89+
\fI/\fR
90+
or
91+
\fI~\fR, it is normalised to a
92+
\fIfile://\fR
93+
URL in the same way as
94+
\fB\-\-add\fR\&. Comments and other entries are preserved\&.
95+
.sp
96+
This command requires write access to
97+
\fBsources.conf\fR(5)
98+
and must typically be run with
99+
\fBsudo\fR\&.
100+
.RE
101+
.SH "GLOBAL OPTIONS"
102+
.sp
103+
Please see the section \fBGLOBAL OPTIONS\fR in the \fBport\fR(1) man page for a description of global port options\&.
104+
.SH "EXAMPLES"
105+
.sp
106+
List the currently configured sources:
107+
.sp
108+
.if n \{\
109+
.RS 4
110+
.\}
111+
.nf
112+
port source
113+
.fi
114+
.if n \{\
115+
.RE
116+
.\}
117+
.sp
118+
Add a local checkout of the MacPorts ports tree for Portfile development, placing it first so it shadows the default remote source and marking it so that \fBport sync\fR leaves it alone:
119+
.sp
120+
.if n \{\
121+
.RS 4
122+
.\}
123+
.nf
124+
sudo port source \-\-add \-\-first \-\-no\-sync ~/src/macports\-ports
125+
.fi
126+
.if n \{\
127+
.RE
128+
.\}
129+
.sp
130+
Add a remote rsync source:
131+
.sp
132+
.if n \{\
133+
.RS 4
134+
.\}
135+
.nf
136+
sudo port source \-\-add rsync://rsync\&.macports\&.org/macports/release/tarballs/ports\&.tar
137+
.fi
138+
.if n \{\
139+
.RE
140+
.\}
141+
.sp
142+
Remove a source by path:
143+
.sp
144+
.if n \{\
145+
.RS 4
146+
.\}
147+
.nf
148+
sudo port source \-\-remove ~/src/macports\-ports
149+
.fi
150+
.if n \{\
151+
.RE
152+
.\}
153+
.sp
154+
Remove a source by URL:
155+
.sp
156+
.if n \{\
157+
.RS 4
158+
.\}
159+
.nf
160+
sudo port source \-\-remove rsync://rsync\&.macports\&.org/macports/release/tarballs/ports\&.tar
161+
.fi
162+
.if n \{\
163+
.RE
164+
.\}
165+
.SH "SEE ALSO"
166+
.sp
167+
\fBport\fR(1), \fBport-sync\fR(1), \fBsources.conf\fR(5)
168+
.SH "AUTHORS"
169+
.sp
170+
.if n \{\
171+
.RS 4
172+
.\}
173+
.nf
174+
(C) 2025 The MacPorts Project
175+
.fi
176+
.if n \{\
177+
.RE
178+
.\}

doc/port-source.1.txt

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// vim: set et sw=4 ts=8 ft=asciidoc tw=80:
2+
port-source(1)
3+
==============
4+
5+
NAME
6+
----
7+
port-source - List, add, and remove MacPorts port tree sources
8+
9+
SYNOPSIS
10+
--------
11+
[cmdsynopsis]
12+
*port* [*-dv*] *source* [--list]
13+
14+
[cmdsynopsis]
15+
*port* [*-dv*] *sudo* *source* *--add* [*--first*] [*--no-sync*] 'url'
16+
17+
[cmdsynopsis]
18+
*port* [*-dv*] *sudo* *source* *--remove* 'url'
19+
20+
DESCRIPTION
21+
-----------
22+
*port source* manages the list of port tree sources configured in
23+
man:sources.conf[5]. Port tree sources tell MacPorts where to find port
24+
definitions (Portfiles).
25+
26+
*port source* has three modes of operation: listing the currently configured
27+
sources, adding a new source, and removing an existing source. See *OPTIONS*
28+
below for details. Changes made by *--add* and *--remove* take effect the next
29+
time *port* is invoked.
30+
31+
A local directory path beginning with '/' or '~' is automatically expanded to a
32+
'file://' URL by both *--add* and *--remove*, making it convenient to manage
33+
local checkouts of the MacPorts ports tree without needing to type the full
34+
'file://' URL.
35+
36+
OPTIONS
37+
-------
38+
*--list*::
39+
Print the currently configured sources, one per line, in the same format
40+
used by man:sources.conf[5]. This is the default when no option is given.
41+
42+
*--add* [*--first*] [*--no-sync*] 'url'::
43+
Add 'url' to the list of port tree sources. If 'url' begins with '/' or
44+
'~', it is interpreted as a local directory path; it will be normalised and
45+
prefixed with 'file://'.
46+
+
47+
By default the new source is appended to the end of man:sources.conf[5].
48+
Use *--first* to insert it before the first existing source entry, which is
49+
useful for a local port tree that should shadow the default remote source.
50+
+
51+
Use *--no-sync* to add the '[nosync]' flag to the entry, preventing
52+
*port sync* from attempting to update this source. This is recommended for
53+
local development checkouts that are managed independently.
54+
+
55+
This command requires write access to man:sources.conf[5] and must typically
56+
be run with *sudo*.
57+
58+
*--remove* 'url'::
59+
Remove the source with the given URL from man:sources.conf[5]. If 'url'
60+
begins with '/' or '~', it is normalised to a 'file://' URL in the same
61+
way as *--add*. Comments and other entries are preserved.
62+
+
63+
This command requires write access to man:sources.conf[5] and must typically
64+
be run with *sudo*.
65+
66+
include::global-flags.txt[]
67+
68+
EXAMPLES
69+
--------
70+
List the currently configured sources:
71+
----
72+
port source
73+
----
74+
75+
Add a local checkout of the MacPorts ports tree for Portfile development,
76+
placing it first so it shadows the default remote source and marking it so
77+
that *port sync* leaves it alone:
78+
----
79+
sudo port source --add --first --no-sync ~/src/macports-ports
80+
----
81+
82+
Add a remote rsync source:
83+
----
84+
sudo port source --add rsync://rsync.macports.org/macports/release/tarballs/ports.tar
85+
----
86+
87+
Remove a source by path:
88+
----
89+
sudo port source --remove ~/src/macports-ports
90+
----
91+
92+
Remove a source by URL:
93+
----
94+
sudo port source --remove rsync://rsync.macports.org/macports/release/tarballs/ports.tar
95+
----
96+
97+
SEE ALSO
98+
--------
99+
man:port[1], man:port-sync[1], man:sources.conf[5]
100+
101+
AUTHORS
102+
-------
103+
(C) 2025 The MacPorts Project

doc/port.1

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,39 @@ sudo port \-d sync
789789
If any of the ports tree(s) uses a file: URL that points to a local subversion working copy, sync will perform an svn update on the working copy with the user set to the owner of the working copy\&.
790790
.RE
791791
.PP
792+
source
793+
.RS 4
794+
List, add, or remove port tree sources from
795+
\fBsources.conf\fR(5)\&. Without a flag,
796+
\fBport source\fR
797+
lists the currently configured sources\&. A local path beginning with
798+
\fI/\fR
799+
or
800+
\fI~\fR
801+
is automatically converted to a
802+
\fIfile://\fR
803+
URL for both
804+
\fB\-\-add\fR
805+
and
806+
\fB\-\-remove\fR\&.
807+
.sp
808+
.if n \{\
809+
.RS 4
810+
.\}
811+
.nf
812+
port source
813+
sudo port source \-\-add \-\-first \-\-no\-sync ~/src/macports\-ports
814+
sudo port source \-\-remove ~/src/macports\-ports
815+
.fi
816+
.if n \{\
817+
.RE
818+
.\}
819+
.sp
820+
See
821+
\fBport-source\fR(1)
822+
for full details\&.
823+
.RE
824+
.PP
792825
outdated
793826
.RS 4
794827
Lists the installed ports which need an

doc/port.1.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,20 @@ subversion working copy, sync will perform an svn update on the working
369369
copy with the user set to the owner of the working copy.
370370
+
371371

372+
source::
373+
List, add, or remove port tree sources from man:sources.conf[5]. Without
374+
a flag, *port source* lists the currently configured sources. A local path
375+
beginning with '/' or '~' is automatically converted to a 'file://' URL
376+
for both *--add* and *--remove*.
377+
+
378+
--------
379+
port source
380+
sudo port source --add --first --no-sync ~/src/macports-ports
381+
sudo port source --remove ~/src/macports-ports
382+
--------
383+
+
384+
See man:port-source[1] for full details.
385+
372386
outdated::
373387
Lists the installed ports which need an 'upgrade'.
374388

0 commit comments

Comments
 (0)