@@ -75,9 +75,9 @@ GIT_EXTERN(int) git_branch_create_from_annotated(
7575/**
7676 * Delete an existing branch reference.
7777 *
78- * If the branch is successfully deleted , the passed reference
79- * object will be invalidated. The reference must be freed manually
80- * by the user .
78+ * Note that if the deletion succeeds , the reference object will not
79+ * be valid anymore, and should be freed immediately by the user using
80+ * `git_reference_free()` .
8181 *
8282 * @param branch A valid reference representing a branch
8383 * @return 0 on success, or an error code.
@@ -126,6 +126,12 @@ GIT_EXTERN(void) git_branch_iterator_free(git_branch_iterator *iter);
126126 * The new branch name will be checked for validity.
127127 * See `git_tag_create()` for rules about valid names.
128128 *
129+ * Note that if the move succeeds, the old reference object will not
130+ + be valid anymore, and should be freed immediately by the user using
131+ + `git_reference_free()`.
132+ *
133+ * @param out New reference object for the updated name.
134+ *
129135 * @param branch Current underlying reference of the branch.
130136 *
131137 * @param new_branch_name Target name of the branch once the move
@@ -145,17 +151,14 @@ GIT_EXTERN(int) git_branch_move(
145151 * Lookup a branch by its name in a repository.
146152 *
147153 * The generated reference must be freed by the user.
148- *
149154 * The branch name will be checked for validity.
150- * See `git_tag_create()` for rules about valid names.
151155 *
152- * @param out pointer to the looked-up branch reference
156+ * @see git_tag_create for rules about valid names.
153157 *
158+ * @param out pointer to the looked-up branch reference
154159 * @param repo the repository to look up the branch
155- *
156160 * @param branch_name Name of the branch to be looked-up;
157161 * this name is validated for consistency.
158- *
159162 * @param branch_type Type of the considered branch. This should
160163 * be valued with either GIT_BRANCH_LOCAL or GIT_BRANCH_REMOTE.
161164 *
@@ -169,116 +172,130 @@ GIT_EXTERN(int) git_branch_lookup(
169172 git_branch_t branch_type );
170173
171174/**
172- * Return the name of the given local or remote branch.
175+ * Get the branch name
176+ *
177+ * Given a reference object, this will check that it really is a branch (ie.
178+ * it lives under "refs/heads/" or "refs/remotes/"), and return the branch part
179+ * of it.
173180 *
174- * The name of the branch matches the definition of the name
175- * for git_branch_lookup. That is, if the returned name is given
176- * to git_branch_lookup() then the reference is returned that
177- * was given to this function.
181+ * @param out Pointer to the abbreviated reference name.
182+ * Owned by ref, do not free.
178183 *
179- * @param out where the pointer of branch name is stored;
180- * this is valid as long as the ref is not freed.
181- * @param ref the reference ideally pointing to a branch
184+ * @param ref A reference object, ideally pointing to a branch
182185 *
183- * @return 0 on success; otherwise an error code (e.g., if the
184- * ref is no local or remote branch) .
186+ * @return 0 on success; GIT_EINVALID if the reference isn't either a local or
187+ * remote branch, otherwise an error code .
185188 */
186189GIT_EXTERN (int ) git_branch_name (
187190 const char * * out ,
188191 const git_reference * ref );
189192
190193/**
191- * Return the reference supporting the remote tracking branch,
192- * given a local branch reference.
194+ * Get the upstream of a branch
193195 *
194- * @param out Pointer where to store the retrieved
195- * reference.
196+ * Given a reference, this will return a new reference object corresponding
197+ * to its remote tracking branch. The reference must be a local branch .
196198 *
199+ * @see git_branch_upstream_name for details on the resolution.
200+ *
201+ * @param out Pointer where to store the retrieved reference.
197202 * @param branch Current underlying reference of the branch.
198203 *
199204 * @return 0 on success; GIT_ENOTFOUND when no remote tracking
200- * reference exists, otherwise an error code.
205+ * reference exists, otherwise an error code.
201206 */
202207GIT_EXTERN (int ) git_branch_upstream (
203208 git_reference * * out ,
204209 const git_reference * branch );
205210
206211/**
207- * Set the upstream configuration for a given local branch
212+ * Set a branch's upstream branch
208213 *
209- * @param branch the branch to configure
214+ * This will update the configuration to set the branch named `name` as the upstream of `branch`.
215+ * Pass a NULL name to unset the upstream information.
210216 *
211- * @param upstream_name remote- tracking or local branch to set as
212- * upstream. Pass NULL to unset .
217+ * @note the actual tracking reference must have been already created for the
218+ * operation to succeed .
213219 *
214- * @return 0 or an error code
220+ * @param branch the branch to configure
221+ * @param branch_name remote-tracking or local branch to set as upstream.
222+ *
223+ * @return 0 on success; GIT_ENOTFOUND if there's no branch named `branch_name`
224+ * or an error code
215225 */
216- GIT_EXTERN (int ) git_branch_set_upstream (git_reference * branch , const char * upstream_name );
226+ GIT_EXTERN (int ) git_branch_set_upstream (
227+ git_reference * branch ,
228+ const char * branch_name );
217229
218230/**
219- * Return the name of the reference supporting the remote tracking branch,
220- * given the name of a local branch reference.
221- *
222- * @param out Pointer to the user-allocated git_buf which will be
223- * filled with the name of the reference.
231+ * Get the upstream name of a branch
224232 *
225- * @param repo the repository where the branches live
233+ * Given a local branch, this will return its remote-tracking branch information,
234+ * as a full reference name, ie. "feature/nice" would become
235+ * "refs/remote/origin/feature/nice", depending on that branch's configuration.
226236 *
237+ * @param out the buffer into which the name will be written.
238+ * @param repo the repository where the branches live.
227239 * @param refname reference name of the local branch.
228240 *
229- * @return 0, GIT_ENOTFOUND when no remote tracking reference exists,
230- * otherwise an error code.
241+ * @return 0 on success , GIT_ENOTFOUND when no remote tracking reference exists,
242+ * or an error code.
231243 */
232244GIT_EXTERN (int ) git_branch_upstream_name (
233245 git_buf * out ,
234246 git_repository * repo ,
235247 const char * refname );
236248
237249/**
238- * Determine if the current local branch is pointed at by HEAD.
250+ * Determine if HEAD points to the given branch
239251 *
240- * @param branch Current underlying reference of the branch.
252+ * @param branch A reference to a local branch.
241253 *
242- * @return 1 if HEAD points at the branch, 0 if it isn't,
243- * error code otherwise .
254+ * @return 1 if HEAD points at the branch, 0 if it isn't, or a negative value
255+ * as an error code.
244256 */
245257GIT_EXTERN (int ) git_branch_is_head (
246258 const git_reference * branch );
247259
248260/**
249- * Determine if the current branch is checked out in any linked
250- * repository.
261+ * Determine if any HEAD points to the current branch
251262 *
252- * @param branch Reference to the branch.
263+ * This will iterate over all known linked repositories (usually in the form of
264+ * worktrees) and report whether any HEAD is pointing at the current branch.
253265 *
254- * @return 1 if branch is checked out, 0 if it isn't,
255- * error code otherwise.
266+ * @param branch A reference to a local branch.
267+ *
268+ * @return 1 if branch is checked out, 0 if it isn't, an error code otherwise.
256269 */
257270GIT_EXTERN (int ) git_branch_is_checked_out (
258271 const git_reference * branch );
259272
260273/**
261- * Return the name of remote that the remote tracking branch belongs to.
274+ * Find the remote name of a remote- tracking branch
262275 *
263- * @param out Pointer to the user-allocated git_buf which will be filled with the name of the remote.
276+ * This will return the name of the remote whose fetch refspec is matching
277+ * the given branch. E.g. given a branch "refs/remotes/test/master", it will
278+ * extract the "test" part. If refspecs from multiple remotes match,
279+ * the function will return GIT_EAMBIGUOUS.
264280 *
281+ * @param out The buffer into which the name will be written.
265282 * @param repo The repository where the branch lives.
283+ * @param refname complete name of the remote tracking branch.
266284 *
267- * @param canonical_branch_name name of the remote tracking branch.
268- *
269- * @return 0, GIT_ENOTFOUND
270- * when no remote matching remote was found,
271- * GIT_EAMBIGUOUS when the branch maps to several remotes,
272- * otherwise an error code.
285+ * @return 0 on success, GIT_ENOTFOUND when no matching remote was found,
286+ * GIT_EAMBIGUOUS when the branch maps to several remotes,
287+ * otherwise an error code.
273288 */
274289GIT_EXTERN (int ) git_branch_remote_name (
275290 git_buf * out ,
276291 git_repository * repo ,
277- const char * canonical_branch_name );
278-
292+ const char * refname );
279293
280294/**
281- * Retrieve the name of the upstream remote of a local branch
295+ * Retrieve the upstream remote of a local branch
296+ *
297+ * This will return the currently configured "branch.*.remote" for a given
298+ * branch. This branch must be local.
282299 *
283300 * @param buf the buffer into which to write the name
284301 * @param repo the repository in which to look
0 commit comments