Skip to content

Commit ca8a36e

Browse files
committed
Merge branch 'js/remote-improvements'
* js/remote-improvements: (23 commits) builtin-remote.c: no "commented out" code, please builtin-remote: new show output style for push refspecs builtin-remote: new show output style remote: make guess_remote_head() use exact HEAD lookup if it is available builtin-remote: add set-head subcommand builtin-remote: teach show to display remote HEAD builtin-remote: fix two inconsistencies in the output of "show <remote>" builtin-remote: make get_remote_ref_states() always populate states.tracked builtin-remote: rename variables and eliminate redundant function call builtin-remote: remove unused code in get_ref_states builtin-remote: refactor duplicated cleanup code string-list: new for_each_string_list() function remote: make match_refs() not short-circuit remote: make match_refs() copy src ref before assigning to peer_ref remote: let guess_remote_head() optionally return all matches remote: make copy_ref() perform a deep copy remote: simplify guess_remote_head() move locate_head() to remote.c move duplicated ref_newer() to remote.c move duplicated get_local_heads() to remote.c ... Conflicts: builtin-clone.c
2 parents a57ca9d + 8321c56 commit ca8a36e

File tree

17 files changed

+820
-330
lines changed

17 files changed

+820
-330
lines changed

Documentation/git-remote.txt

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ SYNOPSIS
1313
'git remote add' [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>
1414
'git remote rename' <old> <new>
1515
'git remote rm' <name>
16+
'git remote set-head' <name> [-a | -d | <branch>]
1617
'git remote show' [-n] <name>
1718
'git remote prune' [-n | --dry-run] <name>
1819
'git remote update' [group]
@@ -53,8 +54,7 @@ is created. You can give more than one `-t <branch>` to track
5354
multiple branches without grabbing all branches.
5455
+
5556
With `-m <master>` option, `$GIT_DIR/remotes/<name>/HEAD` is set
56-
up to point at remote's `<master>` branch instead of whatever
57-
branch the `HEAD` at the remote repository actually points at.
57+
up to point at remote's `<master>` branch. See also the set-head command.
5858
+
5959
In mirror mode, enabled with `\--mirror`, the refs will not be stored
6060
in the 'refs/remotes/' namespace, but in 'refs/heads/'. This option
@@ -76,6 +76,30 @@ the configuration file format.
7676
Remove the remote named <name>. All remote tracking branches and
7777
configuration settings for the remote are removed.
7878

79+
'set-head'::
80+
81+
Sets or deletes the default branch (`$GIT_DIR/remotes/<name>/HEAD`) for
82+
the named remote. Having a default branch for a remote is not required,
83+
but allows the name of the remote to be specified in lieu of a specific
84+
branch. For example, if the default branch for `origin` is set to
85+
`master`, then `origin` may be specified wherever you would normally
86+
specify `origin/master`.
87+
+
88+
With `-d`, `$GIT_DIR/remotes/<name>/HEAD` is deleted.
89+
+
90+
With `-a`, the remote is queried to determine its `HEAD`, then
91+
`$GIT_DIR/remotes/<name>/HEAD` is set to the same branch. e.g., if the remote
92+
`HEAD` is pointed at `next`, "`git remote set-head origin -a`" will set
93+
`$GIT_DIR/refs/remotes/origin/HEAD` to `refs/remotes/origin/next`. This will
94+
only work if `refs/remotes/origin/next` already exists; if not it must be
95+
fetched first.
96+
+
97+
Use `<branch>` to set `$GIT_DIR/remotes/<name>/HEAD` explicitly. e.g., "git
98+
remote set-head origin master" will set `$GIT_DIR/refs/remotes/origin/HEAD` to
99+
`refs/remotes/origin/master`. This will only work if
100+
`refs/remotes/origin/master` already exists; if not it must be fetched first.
101+
+
102+
79103
'show'::
80104

81105
Gives some information about the remote <name>.

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,7 @@ GIT-CFLAGS: .FORCE-GIT-CFLAGS
13811381
GIT-BUILD-OPTIONS: .FORCE-GIT-BUILD-OPTIONS
13821382
@echo SHELL_PATH=\''$(subst ','\'',$(SHELL_PATH_SQ))'\' >$@
13831383
@echo TAR=\''$(subst ','\'',$(subst ','\'',$(TAR)))'\' >>$@
1384+
@echo NO_CURL=\''$(subst ','\'',$(subst ','\'',$(NO_CURL)))'\' >>$@
13841385

13851386
### Detect Tck/Tk interpreter path changes
13861387
ifndef NO_TCLTK

builtin-clone.c

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "dir.h"
2121
#include "pack-refs.h"
2222
#include "sigchain.h"
23+
#include "remote.h"
2324
#include "run-command.h"
2425

2526
/*
@@ -294,43 +295,6 @@ static void remove_junk_on_signal(int signo)
294295
raise(signo);
295296
}
296297

297-
static const struct ref *locate_head(const struct ref *refs,
298-
const struct ref *mapped_refs,
299-
const struct ref **remote_head_p)
300-
{
301-
const struct ref *remote_head = NULL;
302-
const struct ref *remote_master = NULL;
303-
const struct ref *r;
304-
for (r = refs; r; r = r->next)
305-
if (!strcmp(r->name, "HEAD"))
306-
remote_head = r;
307-
308-
for (r = mapped_refs; r; r = r->next)
309-
if (!strcmp(r->name, "refs/heads/master"))
310-
remote_master = r;
311-
312-
if (remote_head_p)
313-
*remote_head_p = remote_head;
314-
315-
/* If there's no HEAD value at all, never mind. */
316-
if (!remote_head)
317-
return NULL;
318-
319-
/* If refs/heads/master could be right, it is. */
320-
if (remote_master && !hashcmp(remote_master->old_sha1,
321-
remote_head->old_sha1))
322-
return remote_master;
323-
324-
/* Look for another ref that points there */
325-
for (r = mapped_refs; r; r = r->next)
326-
if (r != remote_head &&
327-
!hashcmp(r->old_sha1, remote_head->old_sha1))
328-
return r;
329-
330-
/* Nothing is the same */
331-
return NULL;
332-
}
333-
334298
static struct ref *write_remote_refs(const struct ref *refs,
335299
struct refspec *refspec, const char *reflog)
336300
{
@@ -541,7 +505,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
541505

542506
mapped_refs = write_remote_refs(refs, &refspec, reflog_msg.buf);
543507

544-
head_points_at = locate_head(refs, mapped_refs, &remote_head);
508+
remote_head = find_ref_by_name(refs, "HEAD");
509+
head_points_at = guess_remote_head(remote_head, mapped_refs, 0);
545510
}
546511
else {
547512
warning("You appear to have cloned an empty repository.");

0 commit comments

Comments
 (0)