Hash :
39abd3ad
Author :
Date :
2016-11-04T13:39:54
worktree: compute workdir for worktrees opened via their gitdir When opening a worktree via the gitdir of its parent repository we fail to correctly set up the worktree's working directory. The problem here is two-fold: we first fail to see that the gitdir actually is a gitdir of a working tree and then subsequently fail to determine the working tree location from the gitdir. The first problem of not noticing a gitdir belongs to a worktree can be solved by checking for the existence of a `gitdir` file in the gitdir. This file points back to the gitlink file located in the working tree's working directory. As this file only exists for worktrees, it should be sufficient indication of the gitdir belonging to a worktree. The second problem, that is determining the location of the worktree's working directory, can then be solved by reading the `gitdir` file in the working directory's gitdir. When we now resolve relative paths and strip the final `.git` component, we have the actual worktree's working directory location.
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_worktree_h__
#define INCLUDE_worktree_h__
#include "git2/common.h"
#include "git2/worktree.h"
struct git_worktree {
/* Name of the working tree. This is the name of the
* containing directory in the `$PARENT/.git/worktrees/`
* directory. */
char *name;
/* Path to the .git file in the working tree's repository */
char *gitlink_path;
/* Path to the .git directory inside the parent's
* worktrees directory */
char *gitdir_path;
/* Path to the common directory contained in the parent
* repository */
char *commondir_path;
/* Path to the parent's .git directory */
char *parent_path;
int locked:1;
};
char *git_worktree__read_link(const char *base, const char *file);
#endif