Commits

Greg Ward  committed 5f2de63

svn: handle weird checkout dirs better

  • Participants
  • Parent commits dfc398e

Comments (0)

Files changed (2)

 
 #if HAVE_SQLITE3_H
 static int
-svn_read_sqlite(result_t *result)
+svn_read_sqlite(vccontext_t *context, result_t *result)
 {
     int ok = 0;
     int retval;
     result->revision = buf;
     sqlite3_finalize(res);
 
-    sql = "select repos_path from nodes where local_relpath = ''";
+    sql = "select repos_path from nodes where local_relpath = ?";
     retval = sqlite3_prepare_v2(conn, sql, strlen(sql), &res, &tail);
     if (retval != SQLITE_OK) {
         debug("error querying for repos_path");
         goto err;
     }
+    retval = sqlite3_bind_text(res, 1,
+                               context->rel_path, strlen(context->rel_path),
+                               SQLITE_STATIC);
+    if (retval != SQLITE_OK) {
+        debug("error binding parameter");
+        goto err;
+    }
     sqlite3_step(res);
     const unsigned char *repos_path = sqlite3_column_text(res, 0);
     result->branch = get_branch_name((const char *)repos_path);
 }
 #else
 static int
-svn_read_sqlite(result_t *result)
+svn_read_sqlite(vccontext_t *context, result_t *result)
 {
     debug("vcprompt built without sqlite3 (cannot support svn >= 1.7)");
     return 0;
     int ok;
     if (access(".svn/wc.db", F_OK) == 0) {
         // SQLite file format (working copy created by svn >= 1.7)
-        ok = svn_read_sqlite(result);
+        ok = svn_read_sqlite(context, result);
     }
     // First line of the file tells us what the format is.
     else if (isdigit(line[0])) {

File tests/test-svn

 
 pretest()
 {
+    checkout_path=$1
     [ -d $tmpdir ] || die "tmpdir ($tmpdir) does not exist"
     cd $tmpdir
     rm -rf svn-repo svn-wc
     tar -xf $svnrepo
     repourl=file://$tmpdir/svn-repo
-    svn -q checkout $repourl/trunk svn-wc
+    svn -q checkout $repourl/$checkout_path svn-wc
     cd svn-wc
 }
 
 test_basics()
 {
     echo "test_basics:"
-    pretest
+    pretest "trunk"
     assert_vcprompt "vc name" "svn" "%n"
     assert_vcprompt "branch name on trunk" "trunk" "%b"
     assert_vcprompt "rev num on trunk" "2" "%r"
     posttest
 }
 
+test_weird_checkout()
+{
+    # checkout the whole repo, ie. parent of trunk/, tags/, branches/
+    echo "test_weird_checkout:"
+    pretest ""
+    assert_vcprompt "vc name" "svn" "%n"
+    assert_vcprompt "no branch name (in project root)" "" "%b"
+
+    cd trunk
+    assert_vcprompt "branch name on trunk" "trunk" "%b"
+
+    cd ../branches/stable
+    assert_vcprompt "branch name on non-trunk branch" "stable" "%b"
+
+
+    posttest
+}
+
 find_vcprompt
 check_svn
 find_svnrepo
 setup
 
 test_basics
+test_weird_checkout