summaryrefslogtreecommitdiff
path: root/src/revparse.c
diff options
context:
space:
mode:
authorBen Straub <bstraub@github.com>2012-05-03 13:58:46 -0700
committerBen Straub <bstraub@github.com>2012-05-11 11:30:47 -0700
commita6346302e6805aea0f1c353bb62944f1ae7352af (patch)
tree2167320af2d24c0ebdffcbd95d354e1a998336b8 /src/revparse.c
parent65bc26d54aaf307d0e7eb71d6c5752f88fdca5de (diff)
downloadlibgit2-a6346302e6805aea0f1c353bb62944f1ae7352af.tar.gz
Rev-parse: "ref@{upstream}" syntax.
Added tracking configuration to the test repo's config to support unit tests.
Diffstat (limited to 'src/revparse.c')
-rw-r--r--src/revparse.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/revparse.c b/src/revparse.c
index 9719093f6..13778eb11 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -18,6 +18,8 @@
#include "git2/commit.h"
#include "git2/reflog.h"
#include "git2/refs.h"
+#include "git2/repository.h"
+#include "git2/config.h"
GIT_BEGIN_DECL
@@ -173,7 +175,27 @@ static int walk_ref_history(git_object **out, git_repository *repo, const char *
/* @{u} or @{upstream} -> upstream branch, for a tracking branch. This is stored in the config. */
if (!strcmp(reflogspec, "@{u}") || !strcmp(reflogspec, "@{upstream}")) {
- /* TODO */
+ git_config *cfg;
+ if (!git_repository_config(&cfg, repo)) {
+ /* Is the ref a tracking branch? */
+ const char *remote;
+ git_buf_clear(&buf);
+ git_buf_printf(&buf, "branch.%s.remote", refspec);
+ if (!git_config_get_string(cfg, git_buf_cstr(&buf), &remote)) {
+ /* Yes. Find the first merge target name. */
+ const char *mergetarget;
+ git_buf_clear(&buf);
+ git_buf_printf(&buf, "branch.%s.merge", refspec);
+ if (!git_config_get_string(cfg, git_buf_cstr(&buf), &mergetarget) &&
+ !git__prefixcmp(mergetarget, "refs/heads/")) {
+ /* Success. Look up the target and fetch the object. */
+ git_buf_clear(&buf);
+ git_buf_printf(&buf, "refs/remotes/%s/%s", remote, mergetarget+11);
+ retcode = revparse_lookup_fully_qualifed_ref(out, repo, git_buf_cstr(&buf));
+ }
+ }
+ git_config_free(cfg);
+ }
}
/* @{N} -> Nth prior value for the ref (from reflog) */