@@ -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.
@@ -145,17 +145,14 @@ GIT_EXTERN(int) git_branch_move(
145145 * Lookup a branch by its name in a repository.
146146 *
147147 * The generated reference must be freed by the user.
148- *
149148 * The branch name will be checked for validity.
150- * See `git_tag_create()` for rules about valid names.
151149 *
152- * @param out pointer to the looked-up branch reference
150+ * @see git_tag_create for rules about valid names.
153151 *
152+ * @param out pointer to the looked-up branch reference
154153 * @param repo the repository to look up the branch
155- *
156154 * @param branch_name Name of the branch to be looked-up;
157155 * this name is validated for consistency.
158- *
159156 * @param branch_type Type of the considered branch. This should
160157 * be valued with either GIT_BRANCH_LOCAL or GIT_BRANCH_REMOTE.
161158 *
@@ -169,116 +166,130 @@ GIT_EXTERN(int) git_branch_lookup(
169166 git_branch_t branch_type );
170167
171168/**
172- * Return the name of the given local or remote branch.
169+ * Get the branch name
170+ *
171+ * Given a reference object, this will check that it really is a branch (ie.
172+ * it lives under "refs/heads/" or "refs/remotes/"), and return the branch part
173+ * of it.
173174 *
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.
175+ * @param out Pointer to the abbreviated reference name.
176+ * Owned by ref, do not free.
178177 *
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
178+ * @param ref A reference object, ideally pointing to a branch
182179 *
183- * @return 0 on success; otherwise an error code (e.g., if the
184- * ref is no local or remote branch) .
180+ * @return 0 on success; GIT_EINVALID if the reference isn't either a local or
181+ * remote branch, otherwise an error code .
185182 */
186183GIT_EXTERN (int ) git_branch_name (
187184 const char * * out ,
188185 const git_reference * ref );
189186
190187/**
191- * Return the reference supporting the remote tracking branch,
192- * given a local branch reference.
188+ * Get the upstream of a branch
189+ *
190+ * Given a reference, this will return a new reference object corresponding
191+ * to its remote tracking branch. The reference must be a local branch.
193192 *
194- * @param out Pointer where to store the retrieved
195- * reference.
193+ * @see git_branch_upstream_name for details on the resolution.
196194 *
195+ * @param out Pointer where to store the retrieved reference.
197196 * @param branch Current underlying reference of the branch.
198197 *
199198 * @return 0 on success; GIT_ENOTFOUND when no remote tracking
200- * reference exists, otherwise an error code.
199+ * reference exists, otherwise an error code.
201200 */
202201GIT_EXTERN (int ) git_branch_upstream (
203202 git_reference * * out ,
204203 const git_reference * branch );
205204
206205/**
207- * Set the upstream configuration for a given local branch
206+ * Set a branch's upstream branch
208207 *
209- * @param branch the branch to configure
208+ * This will update the configuration to set the branch named `name` as the upstream of `branch`.
209+ * Pass a NULL name to unset the upstream information.
210210 *
211- * @param upstream_name remote- tracking or local branch to set as
212- * upstream. Pass NULL to unset .
211+ * @note the actual tracking reference must have been already created for the
212+ * operation to succeed .
213213 *
214- * @return 0 or an error code
214+ * @param branch the branch to configure
215+ * @param branch_name remote-tracking or local branch to set as upstream.
216+ *
217+ * @return 0 on success; GIT_ENOTFOUND if there's no branch named `branch_name`
218+ * or an error code
215219 */
216- GIT_EXTERN (int ) git_branch_set_upstream (git_reference * branch , const char * upstream_name );
220+ GIT_EXTERN (int ) git_branch_set_upstream (
221+ git_reference * branch ,
222+ const char * branch_name );
217223
218224/**
219- * Return the name of the reference supporting the remote tracking branch,
220- * given the name of a local branch reference.
225+ * Get the upstream name of a branch
221226 *
222- * @param out Pointer to the user-allocated git_buf which will be
223- * filled with the name of the reference.
224- *
225- * @param repo the repository where the branches live
227+ * Given a local branch, this will return its remote-tracking branch information,
228+ * as a full reference name, ie. "feature/nice" would become
229+ * "refs/remote/origin/feature/nice", depending on that branch's configuration.
226230 *
231+ * @param out the buffer into which the name will be written.
232+ * @param repo the repository where the branches live.
227233 * @param refname reference name of the local branch.
228234 *
229- * @return 0, GIT_ENOTFOUND when no remote tracking reference exists,
230- * otherwise an error code.
235+ * @return 0 on success , GIT_ENOTFOUND when no remote tracking reference exists,
236+ * or an error code.
231237 */
232238GIT_EXTERN (int ) git_branch_upstream_name (
233239 git_buf * out ,
234240 git_repository * repo ,
235241 const char * refname );
236242
237243/**
238- * Determine if the current local branch is pointed at by HEAD.
244+ * Determine if HEAD points to the given branch
239245 *
240- * @param branch Current underlying reference of the branch.
246+ * @param branch A reference to a local branch.
241247 *
242- * @return 1 if HEAD points at the branch, 0 if it isn't,
243- * error code otherwise .
248+ * @return 1 if HEAD points at the branch, 0 if it isn't, or a negative value
249+ * as an error code.
244250 */
245251GIT_EXTERN (int ) git_branch_is_head (
246252 const git_reference * branch );
247253
248254/**
249- * Determine if the current branch is checked out in any linked
250- * repository.
255+ * Determine if any HEAD points to the current branch
251256 *
252- * @param branch Reference to the branch.
257+ * This will iterate over all known linked repositories (usually in the form of
258+ * worktrees) and report whether any HEAD is pointing at the current branch.
253259 *
254- * @return 1 if branch is checked out, 0 if it isn't,
255- * error code otherwise.
260+ * @param branch A reference to a local branch.
261+ *
262+ * @return 1 if branch is checked out, 0 if it isn't, an error code otherwise.
256263 */
257264GIT_EXTERN (int ) git_branch_is_checked_out (
258265 const git_reference * branch );
259266
260267/**
261- * Return the name of remote that the remote tracking branch belongs to.
268+ * Find the remote name of a remote- tracking branch
262269 *
263- * @param out Pointer to the user-allocated git_buf which will be filled with the name of the remote.
270+ * This will return the name of the remote whose fetch refspec is matching
271+ * the given branch. E.g. given a branch "refs/remotes/test/master", it will
272+ * extract the "test" part. If refspecs from multiple remotes match,
273+ * the function will return GIT_EAMBIGUOUS.
264274 *
275+ * @param out The buffer into which the name will be written.
265276 * @param repo The repository where the branch lives.
277+ * @param refname complete name of the remote tracking branch.
266278 *
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.
279+ * @return 0 on success, GIT_ENOTFOUND when no matching remote was found,
280+ * GIT_EAMBIGUOUS when the branch maps to several remotes,
281+ * otherwise an error code.
273282 */
274283GIT_EXTERN (int ) git_branch_remote_name (
275284 git_buf * out ,
276285 git_repository * repo ,
277- const char * canonical_branch_name );
278-
286+ const char * refname );
279287
280288/**
281- * Retrieve the name of the upstream remote of a local branch
289+ * Retrieve the upstream remote of a local branch
290+ *
291+ * This will return the currently configured "branch.*.remote" for a given
292+ * branch. This branch must be local.
282293 *
283294 * @param buf the buffer into which to write the name
284295 * @param repo the repository in which to look
0 commit comments