commit - 09f5bd908b0b901f2123f462e4800e76a3d1b10e
commit + bc70eb798d53bf5d6085cba45ef111c713295ed5
blob - 50c0ae77687009bb6ce1cfbb71fb9f8beef20564
blob + 6986c3a84c17dafdf8fd94122de1c579ffde02e0
--- include/got_worktree.h
+++ include/got_worktree.h
/*
* Get the name of a work tree's HEAD reference.
- * The caller must dispose of it with free(3).
*/
-char *got_worktree_get_head_ref_name(struct got_worktree *);
+const char *got_worktree_get_head_ref_name(struct got_worktree *);
/*
* Get the work tree's HEAD reference.
blob - 45237270ff29274f7f93126f03f903dc7e87bbea
blob + 10ad383de5258b5532ef29683628a9ba76caafd8
--- lib/worktree.c
+++ lib/worktree.c
return NULL;
}
-char *
+const char *
got_worktree_get_head_ref_name(struct got_worktree *worktree)
{
- return got_ref_to_str(worktree->head_ref);
+ return got_ref_get_name(worktree->head_ref);
}
struct got_reference *
struct collect_commitables_arg cc_arg;
struct got_pathlist_head commitable_paths;
struct got_pathlist_entry *pe;
- char *relpath = NULL, *head_ref_str = NULL;
+ char *relpath = NULL;
+ const char *head_ref_name = NULL;
struct got_commit_object *base_commit = NULL;
struct got_object_id *head_commit_id = NULL;
struct got_reference *head_ref2 = NULL;
/* Check if a concurrent commit to our branch has occurred. */
/* XXX ideally we'd lock the reference file here to avoid a race */
- head_ref_str = got_ref_to_str(worktree->head_ref);
- if (head_ref_str == NULL) {
+ head_ref_name = got_worktree_get_head_ref_name(worktree);
+ if (head_ref_name == NULL) {
err = got_error_from_errno();
goto done;
}
- err = got_ref_open(&head_ref2, repo, head_ref_str);
+ err = got_ref_open(&head_ref2, repo, head_ref_name);
if (err)
goto done;
err = got_ref_resolve(&head_commit_id2, repo, head_ref2);
free(relpath);
free(head_commit_id);
free(head_commit_id2);
- free(head_ref_str);
if (head_ref2)
got_ref_close(head_ref2);
return err;
blob - e3788886fd140f9ecfccc941118174c1abf7fc12
blob + 30da797e1e9e3e122f6fcba9e8a20c209ca9b677
--- regress/cmdline/commit.sh
+++ regress/cmdline/commit.sh
test_done "$testroot" "$ret"
}
+function test_commit_subdir {
+ local testroot=`test_init commit_subdir`
+
+ got checkout $testroot/repo $testroot/wt > /dev/null
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "modified alpha" > $testroot/wt/alpha
+ echo "modified zeta" > $testroot/wt/epsilon/zeta
+
+ (cd $testroot/wt && \
+ got commit -m 'test commit_subdir' epsilon > $testroot/stdout)
+
+ local head_rev=`git_show_head $testroot/repo`
+ echo "M epsilon/zeta" >> $testroot/stdout.expected
+ echo "created commit $head_rev" >> $testroot/stdout.expected
+
+ cmp $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ fi
+ test_done "$testroot" "$ret"
+}
+
run_test test_commit_basic
run_test test_commit_new_subdir
+run_test test_commit_subdir