سؤال

كيفية إنشاء برنامج نصي لخادم Subversion Server يمنع الأشخاص من ارتكاب تغييرات إذا لم يمتلكوا القفل على الملف أولاً؟

SVN Server على Windows.

شكرًا.

ملاحظة: معلومات إضافية في هذا السؤال

Subversion (SVN + TortoisesVn) ارتكب ملف غير مقفل

هل كانت مفيدة؟

المحلول

استخدم خطافًا مسبقًا. يتلقى خطاف ما قبل الالتزام 2 وسيطات:

#   [1] REPOS-PATH   (the path to this repository)
#   [2] TXN-NAME     (the name of the txn about to be committed)

تحتاج إلى استخدام svnlook لتحديد ما إذا كان هناك SVN: ملفات قفل الاحتياجات غير مقفلة.

لتحديد المسارات التي تغيرت من هذا الالتزام:

svnlook changed $1 --transaction $2

حلقة من خلال الملفات ($PATH كعنصر حلقة) في "تم تغيير" وحدد SVN: احتياجات القفل ، وإذا كانت مغلقة حاليًا:

svnlook propget $REPOS-PATH svn:needs-lock $PATH
svnlook lock $1 $PATH

اكتب إلى stderr وإرجاع غير صفري لإحباط هذا الالتزام عند الحاجة.

نصائح أخرى

يمكنك استخدام <your repos directory>/hooks/pre-commit واستخدم بعض البرمجة النصية الدُفعات (أو حتى برنامجًا كاملًا ، طالما أنه قابل للتنفيذ سيكون جيدًا). إذا عاد 0 الالتزام سيكون ناجحا. وإلا فسوف تفشل.

نرى post-lock.tmpl في نفس الدليل لمثال.

# PRE-COMMIT HOOK
#
# The pre-commit hook is invoked before a Subversion txn is
# committed.  Subversion runs this hook by invoking a program
# (script, executable, binary, etc.) named 'pre-commit' (for which
# this file is a template), with the following ordered arguments:
#
#   [1] REPOS-PATH   (the path to this repository)
#   [2] TXN-NAME     (the name of the txn about to be committed)
#
# The default working directory for the invocation is undefined, so
# the program should set one explicitly if it cares.
#
# If the hook program exits with success, the txn is committed; but
# if it exits with failure (non-zero), the txn is aborted, no commit
# takes place, and STDERR is returned to the client.   The hook
# program can use the 'svnlook' utility to help it examine the txn.
#
# On a Unix system, the normal procedure is to have 'pre-commit'
# invoke other programs to do the real work, though it may do the
# work itself too.
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top