diff options
| author | nulltoken <emeric.fermas@gmail.com> | 2012-04-09 03:22:14 +0200 |
|---|---|---|
| committer | nulltoken <emeric.fermas@gmail.com> | 2012-04-10 21:39:06 +0200 |
| commit | 4615f0f71ba849adef08f7a677842af3e0ee3d53 (patch) | |
| tree | d132b071c0ac313236401b4a2b71a5ee8aebf79d /src | |
| parent | 555aa453baefec98dbd026592b68214048bedac3 (diff) | |
| download | libgit2-4615f0f71ba849adef08f7a677842af3e0ee3d53.tar.gz | |
branch: add git_branch_move()
Diffstat (limited to 'src')
| -rw-r--r-- | src/branch.c | 18 | ||||
| -rw-r--r-- | src/refs.c | 9 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/branch.c b/src/branch.c index c4dbc354d..5efb05b92 100644 --- a/src/branch.c +++ b/src/branch.c @@ -178,3 +178,21 @@ int git_branch_list(git_strarray *branch_names, git_repository *repo, unsigned i branch_names->count = branchlist.length; return 0; } + +int git_branch_move(git_repository *repo, const char *old_branch_name, const char *new_branch_name, int force) +{ + git_reference *reference; + git_buf old_reference_name = GIT_BUF_INIT, new_reference_name = GIT_BUF_INIT; + int error; + + if (git_buf_joinpath(&old_reference_name, GIT_REFS_HEADS_DIR, old_branch_name) < 0) + return -1; + + if (git_buf_joinpath(&new_reference_name, GIT_REFS_HEADS_DIR, new_branch_name) < 0) + return -1; + + if ((error = git_reference_lookup(&reference, repo, git_buf_cstr(&old_reference_name))) < 0) + return error; + + return git_reference_rename(reference, git_buf_cstr(&new_reference_name), force); +} diff --git a/src/refs.c b/src/refs.c index ed364cf90..fb23a0ef8 100644 --- a/src/refs.c +++ b/src/refs.c @@ -287,6 +287,15 @@ static int loose_write(git_reference *ref) if (git_buf_joinpath(&ref_path, ref->owner->path_repository, ref->name) < 0) return -1; + /* Remove a possibly existing empty directory hierarchy + * which name would collide with the reference name + */ + if (git_path_isdir(git_buf_cstr(&ref_path)) && + (git_futils_rmdir_r(git_buf_cstr(&ref_path), GIT_DIRREMOVAL_ONLY_EMPTY_DIRS) < 0)) { + git_buf_free(&ref_path); + return -1; + } + if (git_filebuf_open(&file, ref_path.ptr, GIT_FILEBUF_FORCE) < 0) { git_buf_free(&ref_path); return -1; |
