@@ -234,6 +234,16 @@ static int inherit_tracking(struct tracking *tracking, const char *orig_ref)
return 0;
}
+void install_branch_base(const char *local, const struct object_id *tail)
+{
+ struct strbuf ref = STRBUF_INIT;
+
+ strbuf_addf(&ref, "refs/tails/%s", local);
+ update_ref(NULL, ref.buf, tail, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
+
+ strbuf_release(&ref);
+}
+
/*
* Used internally to set the branch.<new_ref>.{remote,merge} config
* settings so that branch 'new_ref' tracks 'orig_ref'. Unlike
@@ -623,6 +633,8 @@ void create_branch(struct repository *r,
if (real_ref && track)
setup_tracking(ref.buf + 11, real_ref, track, quiet);
+ install_branch_base(ref.buf + 11, &oid);
+
cleanup:
strbuf_release(&ref);
free(real_ref);
@@ -142,6 +142,7 @@ void remove_branch_state(struct repository *r, int verbose);
*/
#define BRANCH_CONFIG_VERBOSE 01
int install_branch_config(int flag, const char *local, const char *origin, const char *remote);
+void install_branch_base(const char *local, const struct object_id *tail);
/*
* Read branch description
@@ -624,6 +624,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
update_ref(msg, "HEAD", &our->old_oid, NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
install_branch_config(0, head, remote_name, our->name);
+ install_branch_base(head, &our->old_oid);
}
} else if (our) {
struct commit *c = lookup_commit_reference(the_repository,
new file mode 100755
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+test_description='test <branch>@{upstream} syntax'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+ echo one > content &&
+ git add content &&
+ git commit -m one &&
+ git checkout -b test master &&
+ echo two > new &&
+ git add new &&
+ git commit -a -m two
+'
+
+test_expect_success 'test tail creation' '
+ git rev-parse refs/tails/test > actual &&
+ git rev-parse master > expect &&
+ test_cmp expect actual
+'
+
+test_done
The 'tail' of a branch points to the first parent commit of the branch when it was created. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> --- branch.c | 12 ++++++++++++ branch.h | 1 + builtin/clone.c | 1 + t/t1514-rev-parse-tail.sh | 23 +++++++++++++++++++++++ 4 files changed, 37 insertions(+) create mode 100755 t/t1514-rev-parse-tail.sh