Skip to content

Commit

Permalink
Merge branch 'maint'
Browse files Browse the repository at this point in the history
* maint:
  remote: create fetch config lines with '+'
  push: allow unqualified dest refspecs to DWIM
  doc/git-gc: add a note about what is collected
  t5516: remove ambiguity test (1)
  Linked glossary from cvs-migration page
  write-tree: properly detect failure to write tree objects
  • Loading branch information
Junio C Hamano committed Apr 25, 2008
2 parents 57cf5ca + 1ce89cc commit 049a226
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 19 deletions.
3 changes: 2 additions & 1 deletion Documentation/cvs-migration.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ designating a single shared repository which people can synchronize with;
this document explains how to do that.

Some basic familiarity with git is required. This
link:tutorial.html[tutorial introduction to git] should be sufficient.
link:tutorial.html[tutorial introduction to git] and the
link:glossary.html[git glossary] should be sufficient.

Developing against a shared repository
--------------------------------------
Expand Down
15 changes: 15 additions & 0 deletions Documentation/git-gc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ The optional configuration variable 'gc.pruneExpire' controls how old
the unreferenced loose objects have to be before they are pruned. The
default is "2 weeks ago".


Notes
-----

git-gc tries very hard to be safe about the garbage it collects. In
particular, it will keep not only objects referenced by your current set
of branches and tags, but also objects referenced by the index, remote
tracking branches, refs saved by linkgit:git-filter-branch[1] in
refs/original/, or reflogs (which may references commits in branches
that were later amended or rewound).

If you are expecting some objects to be collected and they aren't, check
all of those locations and decide whether it makes sense in your case to
remove those references.

See Also
--------
linkgit:git-prune[1]
Expand Down
1 change: 1 addition & 0 deletions builtin-remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ static int add(int argc, const char **argv)
struct path_list_item *item = track.items + i;

strbuf_reset(&buf2);
strbuf_addch(&buf2, '+');
if (mirror)
strbuf_addf(&buf2, "refs/%s:refs/%s",
item->path, item->path);
Expand Down
7 changes: 5 additions & 2 deletions cache-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,11 @@ static int update_one(struct cache_tree *it,

if (dryrun)
hash_sha1_file(buffer.buf, buffer.len, tree_type, it->sha1);
else
write_sha1_file(buffer.buf, buffer.len, tree_type, it->sha1);
else if (write_sha1_file(buffer.buf, buffer.len, tree_type, it->sha1)) {
strbuf_release(&buffer);
return -1;
}

strbuf_release(&buffer);
it->entry_count = i;
#if DEBUG
Expand Down
32 changes: 29 additions & 3 deletions remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,26 @@ static struct ref *make_linked_ref(const char *name, struct ref ***tail)
return ret;
}

static char *guess_ref(const char *name, struct ref *peer)
{
struct strbuf buf = STRBUF_INIT;
unsigned char sha1[20];

const char *r = resolve_ref(peer->name, sha1, 1, NULL);
if (!r)
return NULL;

if (!prefixcmp(r, "refs/heads/"))
strbuf_addstr(&buf, "refs/heads/");
else if (!prefixcmp(r, "refs/tags/"))
strbuf_addstr(&buf, "refs/tags/");
else
return NULL;

strbuf_addstr(&buf, name);
return strbuf_detach(&buf, NULL);
}

static int match_explicit(struct ref *src, struct ref *dst,
struct ref ***dst_tail,
struct refspec *rs,
Expand All @@ -820,6 +840,7 @@ static int match_explicit(struct ref *src, struct ref *dst,
struct ref *matched_src, *matched_dst;

const char *dst_value = rs->dst;
char *dst_guess;

if (rs->pattern)
return errs;
Expand Down Expand Up @@ -866,10 +887,15 @@ static int match_explicit(struct ref *src, struct ref *dst,
case 0:
if (!memcmp(dst_value, "refs/", 5))
matched_dst = make_linked_ref(dst_value, dst_tail);
else if((dst_guess = guess_ref(dst_value, matched_src)))
matched_dst = make_linked_ref(dst_guess, dst_tail);
else
error("dst refspec %s does not match any "
"existing ref on the remote and does "
"not start with refs/.", dst_value);
error("unable to push to unqualified destination: %s\n"
"The destination refspec neither matches an "
"existing ref on the remote nor\n"
"begins with refs/, and we are unable to "
"guess a prefix based on the source ref.",
dst_value);
break;
default:
matched_dst = NULL;
Expand Down
67 changes: 67 additions & 0 deletions t/t0004-unwritable.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/sh

test_description='detect unwritable repository and fail correctly'

. ./test-lib.sh

test_expect_success setup '
>file &&
git add file &&
git commit -m initial &&
echo >file &&
git add file
'

test_expect_success 'write-tree should notice unwritable repository' '
(
chmod a-w .git/objects
test_must_fail git write-tree
)
status=$?
chmod 775 .git/objects
(exit $status)
'

test_expect_success 'commit should notice unwritable repository' '
(
chmod a-w .git/objects
test_must_fail git commit -m second
)
status=$?
chmod 775 .git/objects
(exit $status)
'

test_expect_success 'update-index should notice unwritable repository' '
(
echo a >file &&
chmod a-w .git/objects
test_must_fail git update-index file
)
status=$?
chmod 775 .git/objects
(exit $status)
'

test_expect_success 'add should notice unwritable repository' '
(
echo b >file &&
chmod a-w .git/objects
test_must_fail git add file
)
status=$?
chmod 775 .git/objects
(exit $status)
'

test_done
10 changes: 10 additions & 0 deletions t/t5505-remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ test_expect_success 'add another remote' '
)
'

test_expect_success 'remote forces tracking branches' '
(
cd test &&
case `git config remote.second.fetch` in
+*) true ;;
*) false ;;
esac
)
'

test_expect_success 'remove remote' '
(
cd test &&
Expand Down
54 changes: 41 additions & 13 deletions t/t5516-fetch-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,7 @@ test_expect_success 'push with weak ambiguity (2)' '
'

test_expect_success 'push with ambiguity (1)' '
mk_test remotes/origin/master remotes/frotz/master &&
if git push testrepo master:master
then
echo "Oops, should have failed"
false
else
check_push_result $the_first_commit remotes/origin/master remotes/frotz/master
fi
'

test_expect_success 'push with ambiguity (2)' '
test_expect_success 'push with ambiguity' '
mk_test heads/frotz tags/frotz &&
if git push testrepo master:frotz
Expand Down Expand Up @@ -285,6 +273,37 @@ test_expect_success 'push with colon-less refspec (4)' '
'

test_expect_success 'push head with non-existant, incomplete dest' '
mk_test &&
git push testrepo master:branch &&
check_push_result $the_commit heads/branch
'

test_expect_success 'push tag with non-existant, incomplete dest' '
mk_test &&
git tag -f v1.0 &&
git push testrepo v1.0:tag &&
check_push_result $the_commit tags/tag
'

test_expect_success 'push sha1 with non-existant, incomplete dest' '
mk_test &&
test_must_fail git push testrepo `git rev-parse master`:foo
'

test_expect_success 'push ref expression with non-existant, incomplete dest' '
mk_test &&
test_must_fail git push testrepo master^:branch
'

test_expect_success 'push with HEAD' '
mk_test heads/master &&
Expand Down Expand Up @@ -323,6 +342,15 @@ test_expect_success 'push with +HEAD' '
'

test_expect_success 'push HEAD with non-existant, incomplete dest' '
mk_test &&
git checkout master &&
git push testrepo HEAD:branch &&
check_push_result $the_commit heads/branch
'

test_expect_success 'push with config remote.*.push = HEAD' '
mk_test heads/local &&
Expand Down

0 comments on commit 049a226

Please sign in to comment.