Add git-symbolic-ref

This adds the counterpart of git-update-ref that lets you read
and create "symbolic refs".  By default it uses a symbolic link
to represent ".git/HEAD -> refs/heads/master", but it can be compiled
to use the textfile symbolic ref.

The places that did 'readlink .git/HEAD' and 'ln -s refs/heads/blah
.git/HEAD' have been converted to use new git-symbolic-ref command, so
that they can deal with either implementation.

Signed-off-by: Junio C Hamano <junio@twinsun.com>
This commit is contained in:
Junio C Hamano
2005-09-30 14:26:57 -07:00
committed by Junio C Hamano
parent a876ed83be
commit 8098a178b2
16 changed files with 175 additions and 56 deletions

View File

@ -166,6 +166,7 @@ static void create_default_files(const char *git_dir,
{
unsigned len = strlen(git_dir);
static char path[PATH_MAX];
unsigned char sha1[20];
if (len > sizeof(path)-50)
die("insane git directory %s", git_dir);
@ -186,15 +187,14 @@ static void create_default_files(const char *git_dir,
/*
* Create the default symlink from ".git/HEAD" to the "master"
* branch
* branch, if it does not exist yet.
*/
strcpy(path + len, "HEAD");
if (symlink("refs/heads/master", path) < 0) {
if (errno != EEXIST) {
perror(path);
if (read_ref(path, sha1) < 0) {
if (create_symref(path, "refs/heads/master") < 0)
exit(1);
}
}
path[len] = 0;
copy_templates(path, len, template_path);
}