Thread (1 message) 1 message, 1 author, 2025-02-05

Re: [PATCH v6 7/7] builtin/clone: teach git-clone(1) the --revision= option

From: Junio C Hamano <hidden>
Date: 2025-02-05 17:24:45

Toon Claes [off-list ref] writes:
The git-clone(1) command has the option `--branch` that allows the user
to select the branch they want HEAD to point to. In a non-bare
repository this also checks out that branch.

Option `--branch` also accepts a tag. When a tag name is provided, the
commit this tag points to is checked out and HEAD is detached. Thus
`--branch` can be used to clone a repository and check out a ref kept
under `refs/heads` or `refs/tags`. But some other refs might be in use
as well. For example Git forges might use refs like `refs/pull/<id>` and
`refs/merge-requests/<id>` to track pull/merge requests. These refs
cannot be selected upon git-clone(1).
These examples made the motivation a lot easier to see.  Very nice
compared to a much earlier edition.
+`--revision=<rev>`::
+	Create a new repository, and fetch the history leading to the given
+	revision _<rev>_ (and nothing else), without making any remote-tracking
+	branch, and without making any local branch, and point `HEAD` to
+	_<rev>_. When creating a non-bare repository, the revision is checked
+	out on a detached `HEAD`. The argument can be a ref name
Micronit.  I think the resulting repository, even when it is bare,
would have its HEAD detached (i.e., instead of being a symbolic ref
to a local branch, points directly at a commit object).

	... branch, and detach the `HEAD` to _<rev>_.  When creating
	a non-bare repository, the revision is checked out.  The
	argument can be a ref name ...

But then "When ... checked out" probably goes without saying.  There
is nothing special wrt to bare/non-bare this option affects the
behaviour of the command.
quoted hunk
@@ -580,8 +581,9 @@ static void update_head(const struct ref *our, const struct ref *remote,
 			install_branch_config(0, head, remote_name, our->name);
 		}
 	} else if (our) {
-		struct commit *c = lookup_commit_reference(the_repository,
-							   &our->old_oid);
+		struct commit *c = lookup_commit_or_die(&our->old_oid,
+						        our->name);
+
.git/rebase-apply/patch:62: indent with spaces.
						        our->name);
warning: 1 line applied after fixing whitespace errors.

Other than that, looking good.

Thanks.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help