commit - 00357e4dc78f7f5bd12eceaa07592ab743996e12
commit + 08e5873e99dff11184476ccc3186fbd2a97a2e0b
blob - 319269cc979256b43a557fa7bf838cf0499fdddc
blob + 54b0e26378f33bc033b4126550be4a433a503352
--- got/got.c
+++ got/got.c
{
const struct got_error *error = NULL;
struct got_repository *repo = NULL;
- struct got_reference *head_ref = NULL;
+ struct got_reference *head_ref = NULL, *ref = NULL;
struct got_worktree *worktree = NULL;
char *repo_path = NULL;
char *worktree_path = NULL;
const char *path_prefix = "";
- const char *branch_name = GOT_REF_HEAD;
+ const char *branch_name = GOT_REF_HEAD, *refname = NULL;
char *commit_id_str = NULL;
+ struct got_object_id *commit_id = NULL;
char *cwd = NULL;
int ch, same_path_prefix, allow_nonempty = 0, verbosity = 0;
struct got_pathlist_head paths;
}
if (commit_id_str) {
- struct got_object_id *commit_id;
struct got_reflist_head refs;
TAILQ_INIT(&refs);
error = got_ref_list(&refs, repo, NULL, got_ref_cmp_by_name,
}
error = got_worktree_set_base_commit_id(worktree, repo,
commit_id);
- free(commit_id);
if (error)
goto done;
+ /* Expand potentially abbreviated commit ID string. */
+ free(commit_id_str);
+ error = got_object_id_str(&commit_id_str, commit_id);
+ if (error)
+ goto done;
+ } else {
+ commit_id = got_object_id_dup(
+ got_worktree_get_base_commit_id(worktree));
+ if (commit_id == NULL) {
+ error = got_error_from_errno("got_object_id_dup");
+ goto done;
+ }
+ error = got_object_id_str(&commit_id_str, commit_id);
+ if (error)
+ goto done;
}
error = got_pathlist_append(&paths, "", NULL);
if (error != NULL)
goto done;
+ if (got_ref_is_symbolic(head_ref)) {
+ error = got_ref_resolve_symbolic(&ref, repo, head_ref);
+ if (error)
+ goto done;
+ refname = got_ref_get_name(ref);
+ } else
+ refname = got_ref_get_name(head_ref);
+ printf("Checked out %s: %s\n", refname, commit_id_str);
printf("Now shut up and hack\n");
if (cpa.had_base_commit_ref_error)
show_worktree_base_ref_warning();
done:
+ if (head_ref)
+ got_ref_close(head_ref);
+ if (ref)
+ got_ref_close(ref);
got_pathlist_free(&paths);
free(commit_id_str);
+ free(commit_id);
free(repo_path);
free(worktree_path);
free(cwd);
blob - b6c5784556b7f6d287d651006dc0ccee50de3901
blob + f9066950a272a65b3095aa0b65af01fccd329c41
--- regress/cmdline/checkout.sh
+++ regress/cmdline/checkout.sh
test_checkout_basic() {
local testroot=`test_init checkout_basic`
+ local commit_id=`git_show_head $testroot/repo`
echo "A $testroot/wt/alpha" > $testroot/stdout.expected
echo "A $testroot/wt/beta" >> $testroot/stdout.expected
echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
+ echo "Checked out refs/heads/master: $commit_id" \
+ >> $testroot/stdout.expected
echo "Now shut up and hack" >> $testroot/stdout.expected
got checkout $testroot/repo $testroot/wt > $testroot/stdout
test_checkout_dir_exists() {
local testroot=`test_init checkout_dir_exists`
+ local commit_id=`git_show_head $testroot/repo`
echo "A $testroot/wt/alpha" > $testroot/stdout.expected
echo "A $testroot/wt/beta" >> $testroot/stdout.expected
echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
+ echo "Checked out refs/heads/master: $commit_id" \
+ >> $testroot/stdout.expected
echo "Now shut up and hack" >> $testroot/stdout.expected
mkdir $testroot/wt
test_checkout_dir_not_empty() {
local testroot=`test_init checkout_dir_not_empty`
+ local commit_id=`git_show_head $testroot/repo`
echo "A $testroot/wt/alpha" > $testroot/stdout.expected
echo "A $testroot/wt/beta" >> $testroot/stdout.expected
echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
+ echo "Checked out refs/heads/master: $commit_id" \
+ >> $testroot/stdout.expected
echo "Now shut up and hack" >> $testroot/stdout.expected
mkdir $testroot/wt
chmod +x $testroot/repo/xfile
(cd $testroot/repo && git add .)
git_commit $testroot/repo -m "adding executable file"
+ local commit_id=`git_show_head $testroot/repo`
echo "A $testroot/wt/xfile" > $testroot/stdout.expected
+ echo "Checked out refs/heads/master: $commit_id" \
+ >> $testroot/stdout.expected
echo "Now shut up and hack" >> $testroot/stdout.expected
got checkout $testroot/repo $testroot/wt > $testroot/stdout
test_checkout_tag() {
local testroot=`test_init checkout_tag`
+ local commit_id=`git_show_head $testroot/repo`
local tag="1.0.0"
(cd $testroot/repo && git tag -a -m "test" $tag)
echo "A $testroot/wt/beta" >> $testroot/stdout.expected
echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
+ echo "Checked out refs/heads/master: $commit_id" \
+ >> $testroot/stdout.expected
echo "Now shut up and hack" >> $testroot/stdout.expected
got checkout -c $tag $testroot/repo $testroot/wt > $testroot/stdout
(cd $testroot/repo && git submodule -q add ../repo2)
(cd $testroot/repo && git commit -q -m 'adding submodule')
+ local commit_id=`git_show_head $testroot/repo`
echo "A $testroot/wt/.gitmodules" > $testroot/stdout.expected
echo "A $testroot/wt/alpha" >> $testroot/stdout.expected
echo "A $testroot/wt/beta" >> $testroot/stdout.expected
echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
+ echo "Checked out refs/heads/master: $commit_id" \
+ >> $testroot/stdout.expected
echo "Now shut up and hack" >> $testroot/stdout.expected
got checkout $testroot/repo $testroot/wt > $testroot/stdout
test_checkout_read_only() {
local testroot=`test_init checkout_read_only`
+ local commit_id=`git_show_head $testroot/repo`
# Make the repostiory read-only
chmod -R a-w $testroot/repo
echo "A $testroot/wt/beta" >> $testroot/stdout.expected
echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
+ echo "Checked out refs/heads/master: $commit_id" \
+ >> $testroot/stdout.expected
echo "Now shut up and hack" >> $testroot/stdout.expected
got checkout $testroot/repo $testroot/wt \
test_checkout_into_nonempty_dir() {
local testroot=`test_init checkout_into_nonempty_dir`
+ local commit_id=`git_show_head $testroot/repo`
mkdir -p $testroot/wt
make_test_tree $testroot/wt
echo "? $testroot/wt/beta" >> $testroot/stdout.expected
echo "? $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
echo "? $testroot/wt/gamma/delta" >> $testroot/stdout.expected
+ echo "Checked out refs/heads/master: $commit_id" \
+ >> $testroot/stdout.expected
echo "Now shut up and hack" >> $testroot/stdout.expected
got checkout -E $testroot/repo $testroot/wt > $testroot/stdout
echo "E $testroot/wt/beta" >> $testroot/stdout.expected
echo "E $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
echo "E $testroot/wt/gamma/delta" >> $testroot/stdout.expected
+ echo "Checked out refs/heads/master: $commit_id" \
+ >> $testroot/stdout.expected
echo "Now shut up and hack" >> $testroot/stdout.expected
got checkout -E $testroot/repo $testroot/wt > $testroot/stdout
echo "E $testroot/wt/beta" >> $testroot/stdout.expected
echo "E $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
echo "E $testroot/wt/gamma/delta" >> $testroot/stdout.expected
+ echo "Checked out refs/heads/master: $commit_id" \
+ >> $testroot/stdout.expected
echo "Now shut up and hack" >> $testroot/stdout.expected
got checkout -E $testroot/repo $testroot/wt > $testroot/stdout
(cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
(cd $testroot/repo && git add .)
git_commit $testroot/repo -m "add symlinks"
+ local commit_id=`git_show_head $testroot/repo`
got checkout $testroot/repo $testroot/wt > $testroot/stdout
ret="$?"
echo "A $testroot/wt/nonexistent.link" >> $testroot/stdout.expected
echo "A $testroot/wt/passwd.link" >> $testroot/stdout.expected
echo "A $testroot/wt/passwd2.link" >> $testroot/stdout.expected
+ echo "Checked out refs/heads/master: $commit_id" \
+ >> $testroot/stdout.expected
echo "Now shut up and hack" >> $testroot/stdout.expected
cmp -s $testroot/stdout.expected $testroot/stdout
blob - 487d5e7d9c6ed6c9c2532b3a7fc2dd808e7f3284
blob + f90827299e298d8d6dcedf838627c59d16f80333
--- regress/cmdline/import.sh
+++ regress/cmdline/import.sh
echo "A $testroot/wt/beta" >> $testroot/stdout.expected
echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
+ echo "Checked out refs/heads/main: $head_commit" \
+ >> $testroot/stdout.expected
echo "Now shut up and hack" >> $testroot/stdout.expected
got checkout $testroot/repo $testroot/wt > $testroot/stdout