Branch: Tag:

2017-04-13

2017-04-13 10:21:44 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Added support for tracking branches.

These are a class of branches that essentially behave as movable tags.

557:    }    }    +  int check_not_tracking() +  { +  string local_branch = run_git("symbolic-ref", "HEAD"); +  if (!has_prefix(local_branch, "refs/heads/")) { +  write("Attempt to commit to non-branch: %s.\n", local_branch); +  } +  if (has_prefix(local_branch, "refs/heads/tracking/")) { +  write("Attempt to commit to tracking branch.\n"); +  return 1; +  } +  local_branch = local_branch[sizeof("refs/heads/")..]; +  if (has_suffix(local_branch, "\n")) { +  local_branch = local_branch[..<1]; +  } +  string remote_branch = run_git_ex(1, "config", "--get", +  "branch." + local_branch + ".merge"); +  if (has_prefix(remote_branch, "refs/heads/tracking/")) { +  write("Attempt to commit to remote tracking branch.\n"); +  return 1; +  } +  } +     int hook()    {    files_to_commit =    split_z(run_git("diff", "--staged", "--name-only", "-z"));    attrs = GitAttributes(get_file(".gitattributes", 1));    return -  +  check_not_tracking() |    check_attributes_staged() |    check_blocker_attributes() |    check_gitattributes_files();
579:    ACCESS_NONE = 0,    ACCESS_BASIC = 1,    ACCESS_GROUP = 2, // Create group tags. -  ACCESS_FULL = 3, // rebase/delete branch, move/delete tag, etc. +  ACCESS_EXISTING = 3, // May be updated to any previously existing commit. +  ACCESS_FULL = 4, // rebase/delete branch, move/delete tag, etc.    };       protected mapping(string:AccessLevel) groups = ([
593:    string git_dir = get_git_dir();       groups[user] = ACCESS_FULL; +  groups["tracking"] = ACCESS_EXISTING;       string group_data = Stdio.read_bytes(combine_path(git_dir, "info/group"));   
628:    {    /* Return ACCESS_NONE (0) for no access,    * ACCESS_BASIC (1) for basic access, and -  * ACCESS_FULL (2) for full access +  * ACCESS_FULL (4) for full access    * (including rebase/delete branch, and move/delete tag)    */    string shortref = ref_name;
691:    return 0;    } else if (new_sha == "0"*40) {    // Delete old branch -  if (access_level < ACCESS_FULL) { +  if (access_level < ACCESS_EXISTING) {    write("You may not delete branches which do not belong to you.\n");    return 1;    }    return 0;    } else { -  if (access_level >= ACCESS_FULL) +  // FIXME: Ought to ensure that the commit allready exists +  // for ACCESS_EXISTING. +  if (access_level >= ACCESS_EXISTING)    /* Skip checks */    return 0;