@@ -290,3 +290,50 @@ void test_path_core__isvalid_dotgit_with_hfs_ignorables(void)
290290 cl_assert_equal_b (true, git_path_isvalid (NULL , ".git\xe2\x80\xbf" , GIT_PATH_REJECT_DOT_GIT_HFS ));
291291 cl_assert_equal_b (true, git_path_isvalid (NULL , ".git\xe2\xab\x81" , GIT_PATH_REJECT_DOT_GIT_HFS ));
292292}
293+
294+ static void test_join_unrooted (
295+ const char * expected_result ,
296+ ssize_t expected_rootlen ,
297+ const char * path ,
298+ const char * base )
299+ {
300+ git_buf result = GIT_BUF_INIT ;
301+ ssize_t root_at ;
302+
303+ cl_git_pass (git_path_join_unrooted (& result , path , base , & root_at ));
304+ cl_assert_equal_s (expected_result , result .ptr );
305+ cl_assert_equal_i (expected_rootlen , root_at );
306+
307+ git_buf_free (& result );
308+ }
309+
310+ void test_path_core__join_unrooted (void )
311+ {
312+ git_buf out = GIT_BUF_INIT ;
313+
314+ test_join_unrooted ("foo" , 0 , "foo" , NULL );
315+ test_join_unrooted ("foo/bar" , 0 , "foo/bar" , NULL );
316+
317+ /* Relative paths have base prepended */
318+ test_join_unrooted ("/foo/bar" , 4 , "bar" , "/foo" );
319+ test_join_unrooted ("/foo/bar/foobar" , 4 , "bar/foobar" , "/foo" );
320+ test_join_unrooted ("c:/foo/bar/foobar" , 6 , "bar/foobar" , "c:/foo" );
321+ test_join_unrooted ("c:/foo/bar/foobar" , 10 , "foobar" , "c:/foo/bar" );
322+
323+ /* Absolute paths are not prepended with base */
324+ test_join_unrooted ("/foo" , 0 , "/foo" , "/asdf" );
325+ test_join_unrooted ("/foo/bar" , 0 , "/foo/bar" , "/asdf" );
326+
327+ /* Drive letter is given as root length on Windows */
328+ test_join_unrooted ("c:/foo" , 2 , "c:/foo" , "c:/asdf" );
329+ test_join_unrooted ("c:/foo/bar" , 2 , "c:/foo/bar" , "c:/asdf" );
330+
331+ /* Base is returned when it's provided and is the prefix */
332+ test_join_unrooted ("c:/foo/bar/foobar" , 6 , "c:/foo/bar/foobar" , "c:/foo" );
333+ test_join_unrooted ("c:/foo/bar/foobar" , 10 , "c:/foo/bar/foobar" , "c:/foo/bar" );
334+
335+ /* Trailing slash in the base is ignored */
336+ test_join_unrooted ("c:/foo/bar/foobar" , 6 , "c:/foo/bar/foobar" , "c:/foo/" );
337+
338+ git_buf_free (& out );
339+ }
0 commit comments