Re: [PATCH v3 23/25] checkout: detach if the branch is already checked out elsewhere

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Feb 18, 2014 at 8:40 AM, Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> wrote:
> The normal rule is anything outside refs/heads/ is detached. This
> strictens the rule a bit more: if the branch is checked out (either in

s/strictens/increases strictness of/

> $GIT_COMMON_DIR/HEAD or any $GIT_DIR/repos/.../HEAD) then it's
> detached as well.
>
> A hint is given so the user knows where to go and do something there
> if they still want to checkout undetached here.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
> ---
> diff --git a/builtin/checkout.c b/builtin/checkout.c
> index f961604..7b86f2b 100644
> --- a/builtin/checkout.c
> +++ b/builtin/checkout.c
> @@ -433,6 +433,11 @@ struct branch_info {
>         const char *name; /* The short name used */
>         const char *path; /* The full name of a real branch */
>         struct commit *commit; /* The named commit */
> +       /*
> +        * if not null the branch is detached because it's alrady

s/alrady/already/

> +        * checked out in this checkout
> +        */
> +       char *checkout;
>  };
>
> +static void check_linked_checkouts(struct branch_info *new)
> +{
> +       struct strbuf path = STRBUF_INIT;
> +       DIR *dir;
> +       struct dirent *d;
> +
> +       strbuf_addf(&path, "%s/repos", get_git_common_dir());
> +       if ((dir = opendir(path.buf)) == NULL)

strbuf_release(&path);

> +               return;
> +
> +       strbuf_reset(&path);
> +       strbuf_addf(&path, "%s/HEAD", get_git_common_dir());
> +       /*
> +        * $GIT_COMMON_DIR/HEAD is practically outside
> +        * $GIT_DIR so resolve_ref_unsafe() won't work (it
> +        * uses git_path). Parse the ref ourselves.
> +        */
> +       if (check_linked_checkout(new, "", path.buf)) {
> +               strbuf_release(&path);
> +               closedir(dir);
> +               return;
> +       }
> +
> +       while ((d = readdir(dir)) != NULL) {
> +               if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
> +                       continue;
> +               strbuf_reset(&path);
> +               strbuf_addf(&path, "%s/repos/%s/HEAD",
> +                           get_git_common_dir(), d->d_name);
> +               if (check_linked_checkout(new, d->d_name, path.buf))
> +                       break;
> +       }
> +       strbuf_release(&path);
> +       closedir(dir);
> +}
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]